【HDU1000】A+B Problem

题目来源:www.acm.hdu.edu.cn

题目编号:1000  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
 
 /*-----------------------------题目翻译-----------------------------*/
 
【问题描述】
 计算A+B的值
 
【输入】
 每行包括两个整形数A和B。
 
【输出】
 对于每个示例,在一行中输出A+B的结果。
 
【样例输入】
 1 1
 
【样例输出】
 2
 
 
 
/*-----------------------------题目分析-----------------------------*/

在本题中,你的任务是计算两个整型数A + B之和。

题目的目的主要在于让你能够熟悉OJ中常见的输入输出格式。

 

 

 /*------------------------------Code------------------------------*/

Judge Status : Accepted

Language:C

 

 1 #include<stdio.h>
 2 
 3 int main()
 4 {
 5     int a,b;                          //定义变量
 6     while(scanf("%d %d",&a,&b)!=EOF)  //特别注意此处格式
 7     {
 8         printf("%d\n",a+b);           //多个输出样例,每个后要换行
 9     }
10     return 0;
11 }

 

特别注意,如下代码形式是不正确的(以下代码将被评判为WA)

/*Wrong Code*/

 1 #include<stdio.h>
 2 
 3 int main()
 4 {
 5     int a,b;
 6 //while(1){
 7     scanf("%d %d",&a,&b);
 8     printf("%d",a+b);
 9 //}
10 //若加了while(1)循环则被判为TLM
11 }

 

 

 

posted on 2016-02-15 16:45  南漂者  阅读(176)  评论(0编辑  收藏  举报