今天心血来潮试了下几个OJ网站
ZOJ和51nod,试了个最简单的1001题就出了问题
ZOJ Problem Set - 1001A + B Problem
Time Limit: 2 Seconds Memory Limit: 65536 KB
Calculate a + b
Input
The input will consist of a series of pairs of integers a and b,separated by a space, one pair of integers per line.
Output
For each pair of input integers a and b you should output the sum of a and b in one line,and with one line of output for each line in input.
Sample Input
1 5
Sample Output
6
Hint
Use + operator
用C++做了下
#include <iostream>
using namespace std;
int main()
{
int a, b;
while (cin >> a >> b)
{
cout << a + b << endl;
}
return 0;
}
没问题,然后想用python再试下
print sum(map(int, raw_input().split()))
本机测试没问题,提交就出错,看了下zoj给的测试用例,我自己跑却是死循环。又去51nod上试了下,上面的代码没问题AC了,百思不得其解,为啥在ZOJ上总是WRONG,而且他的例子我还跑不起来,然后百度了下,发现是我太low了,
原因是我的代码只输出了第一行的两个数的和。。
而zoj的标准输入里面有好多行的测试数据,51nod估计测试用例也简单
至于zoj的例子是我忘了按Ctrl+Z了。。。
import sys
for line in sys.stdin:
a = line.split()
print int(a[0])+int(a[1])

本文详细记录了作者在尝试使用C++和Python两种编程语言解决ZOJ平台上的1001题时遇到的问题,重点讨论了在不同环境下输出结果的差异,并最终通过调试和理解标准输入格式找到了解决方案。
11万+

被折叠的 条评论
为什么被折叠?



