競技プログラミングの鉄則
次の問題へ
前の問題へ
A28 Blackboard
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("4");
WillReturn.Add("+ 57");
WillReturn.Add("+ 43");
WillReturn.Add("* 100");
WillReturn.Add("- 1");
//57
//100
//0
//9999
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
long CurrVal = 0;
foreach (string EachStr in InputList.Skip(1)) {
string[] SplitArr = EachStr.Split(' ');
long AVal = long.Parse(SplitArr[1]);
if (SplitArr[0][0] == '+') {
CurrVal += AVal;
}
if (SplitArr[0][0] == '-') {
CurrVal -= AVal;
}
if (SplitArr[0][0] == '*') {
CurrVal *= AVal;
}
CurrVal %= 10000;
if (CurrVal < 0) CurrVal += 10000;
Console.WriteLine(CurrVal);
}
}
}
解説
細めにmodを取ってます。