竞赛讨论区 > 哪个大神帮我看一下为什么在牛客网上会报错,本地编译器上没错
头像
牛客879991494号
发布于 2023-11-13 21:44
+ 关注

哪个大神帮我看一下为什么在牛客网上会报错,本地编译器上没错

题目:

A+B(1)计算a+b打开以下链接可以查看正确的代码1https://ac.nowcoder.com/acm/contest/5657#question数据范围: 数据组数1≤�≤100

1≤t≤100 , 数据大小满足1≤�≤1000

1≤n≤1000时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 256M,其他语言512M输入描述:输入包括两个正整数a,b(1 <= a, b <= 1000),输入数据包括多组。输出描述:输出a+b的结果

代码:

public static void Main()

{

string line;

List<string> numbers = new List<string>();

while ((line = System.Console.ReadLine()) != null)

{ // 注意 while 处理多个 case

numbers.Add(line);

}

foreach (var number in numbers)

{

string[] tokens = number.Split(",");

int sum = 0;

for (int i = 0; i < tokens.Length; i++)

{

sum = sum + int.Parse(tokens[i]);

}

System.Console.WriteLine(sum);

}

}

错误:程序异常退出, 请检查代码"是否有数组越界等异常"或者"是否有语法错误"Unhandled Exception:System.FormatException: Input string was not in a correct format.at System.Number.ThrowOverflowOrFormatException (System.Boolean overflow, System.String overflowResourceKey) [0x0001a] in :0at System.Number.ParseInt32 (System.ReadOnlySpan1[T] value, System.Globalization.NumberStyles styles, System.Globalization.NumberFormatInfo info) [0x00016] in :0 at System.Int32.Parse (System.String s) [0x00016] in :0 at Program.Main () [0x0004b] in :0 [ERROR] FATAL UNHANDLED EXCEPTION: System.FormatException: Input string was not in a correct format. at System.Number.ThrowOverflowOrFormatException (System.Boolean overflow, System.String overflowResourceKey) [0x0001a] in :0 at System.Number.ParseInt32 (System.ReadOnlySpan1[T] value, System.Globalization.NumberStyles styles, System.Globalizat...

全部评论

(2) 回帖
加载中...
话题 回帖

等你来战

查看全部

热门推荐