今天在杭电acm这里做的第一道题 A + B Problem,它的要求是
Problem Description Calculate A + B. Input Each line will contain two integers A and B.Process to end of file. Output For each case, output A + B in one line. Sample Input 1 1 Sample Output 2。
这里的Process to end of file. 到底是什么鬼?翻译过来就是一直 处理到文件的结束,或把数据输出到文件的末尾,可这怎么处理啊?纠结了半天才知道,Process to end of file.简单的来说它表示的是输入时从文件读进来的,我们需要一直处理到文件末尾。一般的处理方法是通过while(gets(x))(x是字符串)或者while(scanf("%d",&n)!=EOF)来处理.
代码如下:
#include <stdio.h>
int main()
{
int a,b,c;
while(scanf("%d%d",&a,&b)!=EOF)
{
c=a+b;
printf("%d\n",c); //此处n如果删掉就会报错
}
return 0;
}