using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Windows.Forms;
class Program
{
struct InOutInfoDef
{
internal List<string> InStrList;
internal List<string> OutStrList;
}
static List<InOutInfoDef> mInOutInfoList = new List<InOutInfoDef>();
[STAThreadAttribute]
static void Main()
{
string TargetStr = DeriveTargetStr();
string[] LineDataArr =
TargetStr.Split(new string[] { Environment.NewLine },
StringSplitOptions.None);
var InOutInfoDef = new List<InOutInfoDef>();
bool IsInput = false;
bool IsOutput = false;
var wkInStrList = new List<string>(); ;
var wkOutStrList = new List<string>(); ;
foreach (string EachLine in LineDataArr) {
if (Regex.IsMatch(EachLine, @"^<h3>入力例 [0-9]+</h3><pre>")) {
IsInput = true; IsOutput = false;
}
if (Regex.IsMatch(EachLine, @"^<h3>出力例 [0-9]+</h3><pre>")) {
IsInput = false; IsOutput = true;
}
if (EachLine.StartsWith("</pre>")) {
if (IsOutput) {
InOutInfoDef WillAdd;
WillAdd.InStrList = new List<string>(wkInStrList);
WillAdd.OutStrList = new List<string>(wkOutStrList);
mInOutInfoList.Add(WillAdd);
wkInStrList.Clear();
wkOutStrList.Clear();
}
IsInput = IsOutput = false;
}
if (IsInput) {
string wkStr =
Regex.Replace(EachLine, @"^<h3>入力例 [0-9]+</h3><pre>(.*)$", "$1");
wkInStrList.Add(wkStr);
}
if (IsOutput) {
string wkStr =
Regex.Replace(EachLine, @"^<h3>出力例 [0-9]+</h3><pre>(.*)$", "$1");
wkOutStrList.Add(wkStr);
}
}
//GetInputListメソッド用のIF文を作成
CreateIfStatement();
}
//スクレイピング対象のString型を返す
static string DeriveTargetStr()
{
IDataObject iData = Clipboard.GetDataObject();
if (iData.GetDataPresent(DataFormats.Text))
return iData.GetData(DataFormats.Text).ToString();
return "";
}
//GetInputListメソッド用のIF文を作成
static void CreateIfStatement()
{
var StrList = new List<string>();
for (int I = 0; I <= mInOutInfoList.Count - 1; I++) {
string wkStr1 =
string.Format(@"{0} (InputPattern == ""Input{1}"") {{",
I == 0 ? "if" : "else if", I + 1);
StrList.Add(wkStr1);
foreach (string EachStr in mInOutInfoList[I].InStrList) {
string wkStr2 =
string.Format(@" WillReturn.Add(""{0}"");", EachStr);
StrList.Add(wkStr2);
}
foreach (string EachStr in mInOutInfoList[I].OutStrList) {
string wkStr3 =
string.Format(@" //{0}", EachStr);
StrList.Add(wkStr3);
}
StrList.Add("}");
}
var sb = new System.Text.StringBuilder();
StrList.ForEach(X => sb.AppendLine(X));
Console.Write(sb.ToString());
Clipboard.SetDataObject(sb.ToString(), true);
}
}