トップページに戻る
次の競技プログラミングのテンプレートへ
001 競技プログラミングのテンプレート C#
競技プログラミングのC#のテンプレートです。
C#のソース
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "Input1";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("");
}
else if (InputPattern == "Input2") {
WillReturn.Add("");
}
else if (InputPattern == "Input3") {
WillReturn.Add("");
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static long[] GetSplitArr(string pStr)
{
return (pStr == "" ? new string[0] : pStr.Split(' ')).Select(pX => long.Parse(pX)).ToArray();
}
static void Main()
{
List<string> InputList = GetInputList();
//long[] wkArr = GetSplitArr(InputList[0]);
//long[] wkArr = { };
//Action<string> SplitAct = (pStr) => wkArr = GetSplitArr(pStr);
}
}
解説
List<string>ではなく、IEnumerable<string>を使用するようにして、
Yield Returnを使ってもいいです。
AOJやyukicoderのWAの原因調査で、テキストファイルから入力を受け入れる場合は、
System.IO.File.ReadAllLines(@"テキストファイルのフルパス").ToList();
という記述が使えます。