hdu 1000

杭电第一题

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

#include <stdio.h>
int main(void)
{
    int a, b;
    while (scanf("%d %d", &a, &b)==2)
        printf("%d
",a+b);
    return 0;
}

这是我的答案,和hoj第一题一样。。。看到each line 果断while循环。AC了

不过网上也有这样一种答案:

#include<stdio.h>

int main()
{
 int a,b;
 while(scanf("%d %d",&a,&b)!=EOF)
 {
  printf("%d
",a+b);
 }
 return 0;
}

一看到EOF,又去查字典了,原来最后一句话是程序进行到文件尾的意思。所以还是第二种答案更好。

同时在网上看到了一种说法,就算题目没有说进行到文件尾的时候结束,也默认是这样得加EOF。看来自己还是差太多。

原文地址:https://www.cnblogs.com/kugwzk/p/5045592.html