提示
OnlineJudge 上一些关于输入输出和编译的注意事项:
1 Sample Input 和 Sample Output只是例子,而Judge处会有更全面的数据,所以,通过Sample的测试未必能通过Judge的测试。
2 scanf有返回值,返回输入参数的个数,可以利用此返回值判断输入的结束。
3 不需要等全部输入完毕再处理,可以每组数据处理完之后输出答案,再读入下一组数据进行计算。
4 由于Judge处对输出严格检查,所以不要输出答案之外的其他信息,否则不会通过测试。
5 提交的时候语言虽然是C++,但是只要注意用int main() 并且主函数 return 0 ,仍然可以用C风格编写程序。
6 编写程序的时候注意包含必要的头文件(如printf要用到stdio.h), 防止不必要的编译错误。
7 Judge 用的是32位GCC编译器,而TurboC是16位编译器,所以数据范围不一样。
8 注意VC中临时循环变量的有效域问题。如 for(int i =0;i<100;i++) i = 99; i = 99; 能通过VC的编译,但是却不符合标准C++语法,所以在Judge处将会产生编译错误。
9 注意包含适当的头文件。例如,用到scanf,printf等函数,需要包含stdio.h; 用到sin,cos等函数,需要包含math.h。
另:本编译器不提供标准C/C++以外的头文件,如stdafx.h.
1000参考解答
C语言
#include <stdio.h>
int main()
{
int a,b;
while (scanf("%d%d",&a,&b)!=EOF)
printf("%d\n",a+b);
return 0;
}
C++语言
#include <iostream>
using namespace std;
int main()
{
int a,b;
while (cin>>a>>b) cout<<a+b<<endl;
return 0;
}
Pascal语言
var
a,b:integer;
begin
while not eof do begin
readln(a,b);
writeln(a+b);
end;
end.
1000问题(作为参考的样本...)
A+B Problem
--------------------------------------------------------------------------------
Time Limit:3s Memory limit:32M
Accepted Submit:2041 Total Submit:4284
--------------------------------------------------------------------------------
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
2 3
Sample Output
6
5