using System; using System.Collections.Generic; using System.Text.RegularExpressions; class Program { static string InputPattern = "InputX"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("5+3"); //2 //入力は5+3ですが、5 - 3の演算の結果である2を出力します。 } else if (InputPattern == "Input2") { WillReturn.Add("10-20"); //30 } else if (InputPattern == "Input3") { WillReturn.Add("-2+-3"); //1 //入力のx,yが符号を含む場合があります。 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List InputList = GetInputList(); Match InsMatch = Regex.Match(InputList[0], @"([-+]?[0-9]+)([-+])([-+]?[0-9]+)$"); int X = int.Parse(InsMatch.Groups[1].Value); string Ope = InsMatch.Groups[2].Value; int Y = int.Parse(InsMatch.Groups[3].Value); if (Ope == "+") Console.WriteLine(X - Y); else Console.WriteLine(X + Y); } }