杭电oj-1000-A+B

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

 

 问题分析:

  此题可以说是该oj上最简单的题目了,但是对于刚入门程序设计竞赛的人来说,如果没有理解“Process to end of file.”这句话的意思,将无法做对,这句话是说,整个运行过程直到文件末尾,也就是说,它是没有限定输入的量,因此我们要使用 while(scanf("%d%d",&a,&b)!=EOF) 这条语句来达到这个目的,这个方法在刘汝佳《算法竞赛经典入门》中是有提到过的,要想使输入结束,我们只需要将CTRL+Z按完之后,再敲击回车即可终止程序的运行。

 

 Code:

1 #include<iostream>
2 using namespace std;
3 int main(){
4     int  a=0,b=0;
5     while(scanf("%d%d",&a,&b)!=EOF)//Ctrl+z时即可将其终止 
6     cout<<a+b<<endl;
7     return 0;
8 }

 

posted @ 2018-03-18 16:25  Do_Better  阅读(1459)  评论(0编辑  收藏  举报