AtCoderのARC
前のARCの問題へ
ARC198-A I hate 1
C#のソース
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("5");
//2
//3 5
}
else if (InputPattern == "Input2") {
WillReturn.Add("2");
//1
//2
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
long N = long.Parse(InputList[0]);
if (N == 1) {
Console.WriteLine(1);
Console.WriteLine(1);
return;
}
var AnswerList = new List<long>();
for (long I = 2; I <= N; I += 2) {
AnswerList.Add(I);
}
Console.WriteLine(AnswerList.Count);
Console.WriteLine(LongEnumJoin(" ", AnswerList));
}
// セパレータとLong型の列挙を引数として、結合したstringを返す
static string LongEnumJoin(string pSeparater, IEnumerable<long> pEnum)
{
string[] StrArr = Array.ConvertAll(pEnum.ToArray(), pX => pX.ToString());
return string.Join(pSeparater, StrArr);
}
}
解説
考察すると、偶数を順に選べば良いと分かります。