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 }