首页 > 其他 > 详细

HDoj 1089 A+B for Input-Output Practice (I)

时间:2020-03-09 16:23:02      阅读:50      评论:0      收藏:0      [点我收藏+]

/*
A+B for Input-Output Practice (I)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 213862 Accepted Submission(s): 110125


Problem Description
Your task is to Calculate a + b.
Too easy?! Of course! I specially designed the problem for acm beginners.
You must have found that some problems have the same titles with this one, yes, all these problems were designed for the same aim.


Input
The input will consist of a series of pairs 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
1 5
10 20


Sample Output
6
30


Author
lcy


Recommend
JGShining

*/

 

在本题中要注意最后终止输入时该怎么判断,并且让程序结束,以本题为例,

如果是C语言,那就是 while(  scanf("%d%d",&a,&b)  !=  EOF)   在自己的控制台上,按下CTRL+Z(也就是EOF字符)再回车来告诉程序输入结束, 在oj上并不是键盘敲击输入数据的而是读入文本数据实现,在oj平台上数据结束末尾默认加上一个EOF字符。所以用上述方法判断。

C++上直接是  while( cin>>a>>b )     在自己的控制台上,按下CTRL+Z(也就是EOF字符)在回车,cin>>a>>b返回0,中断输入,如果在oj上读文本数据,读到末尾的EOF也是返回0,中断输入。

 

C++语言代码以下:

#include<iostream>
using namespace std;
int main()
{

    int a,b;
    while(cin>>a>>b)
    cout<<a+b<<endl;
}

 

HDoj 1089 A+B for Input-Output Practice (I)

原文:https://www.cnblogs.com/wzmm/p/12449349.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!