简单题:Your task is to Calculate a + b.

来源:互联网 发布:51电子单片机原理图 编辑:程序博客网 时间:2024/06/06 21:40
Input
     Input contains an integer N in the first line, and then N lines follow. Each line consists of a pair 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:
     2 
     1 5 
     10 20 


Sample output:
     6

     30


#include<iostream>#include<stdio.h>using namespace std;int main(void){int n,x,y;scanf("%d",&n);while(n--){if(scanf("%d%d",&x,&y)!=EOF)printf("%d\n",x+y);}return 0;}


如果输入的终止条件不是n,而是输入了0 0,那么代码就变成了下面这样:

#include<iostream>#include<stdio.h>using namespace std;int main(void){int x,y;while(scanf("%d%d",&x,&y) &&(x!=0 || y!=0)){printf("%d\n",x+y);}return 0;}



0 0
原创粉丝点击