using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace ConsoleApp3
{
class Program1
{
static void Main(string[] args)
{
List<int> list = new List<int>();
string s;
while (true)
{
if (list.Count==0)
{
Console.Write("第" + 1 + "组数据为:");
}
s = Console.ReadLine();//存储输入
//输入符合要求时
if (Regex.IsMatch(s, "^([1][0][0]|[1-9][0-9]|[1-9]){1}(\\s+)([1][0][0]|[1-9][0-9]|[1-9]){1}$"))
{
string[] s2 = s.Split(' ');
list.Add(Convert.ToInt32(s2[0]) + Convert.ToInt32(s2[1]));
Console.Write("第" + (list.Count+1) + "组数据为:");
}
else//输入不符合要求时
{
if (String.IsNullOrEmpty(s))//直接回车会输出之前每组数据答案
{
for (int i = 0; i < list.Count; i++)
{
Console.Write("第" + (i+1) + "组数据之和为:");
Console.WriteLine(list[i]);
}
list = new List<int>();
}
else//输入错误提示
{
Console.WriteLine("第" + (list.Count + 1) + "组数据输入格式有误");
Console.Write("第" + (list.Count + 1) + "组数据为:");
}
}
}
}
}
}
hihoCoder题二:A + B详解
猜你喜欢
转载自blog.csdn.net/weixin_41995872/article/details/80373346
今日推荐
周排行