Chinaunix首页 | 论坛 | 博客
  • 博客访问: 157165
  • 博文数量: 22
  • 博客积分: 828
  • 博客等级: 上士
  • 技术积分: 290
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-01 18:16
文章分类

全部博文(22)

文章存档

2012年(22)

分类: C/C++

2012-05-23 12:36:49

因为电脑原因,只做了一题,这里就写一个了
A+B for Input-Output Practice (I)
Time Limit:1000MS  Memory Limit:10000K(题目的运行时间和内存限制)
Total Submit:111 Accepted:36 (当前提交总次数 正确次数)
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
   
    这是一个求两数之和的题目,输入用空格分开的两个数a b,输出a+b的结果。编写代码时需要注意的是,本题的输入数据不是只有一对数据,而是多对数据,每对数据占一行。因为没有指出共有多少对输入数据,于是我们可以编写如下代码:

点击(此处)折叠或打开

  1. #include <stdio.h>

  2. int main() //把main函数定义成int类型

  3. {

  4.       int a,b;

  5.       while(scanf("%d %d",&a, &b) != EOF) // 输入文件结束时,scanf函数返回值为EOF

  6.            printf("%d\n",a+b); // 直到没有数据输入则退出while循环

  7.       return 0;
  8. }

  9. //或者C++语言

  10. #include <iostream>

  11. using namespace std;

  12. int main()

  13. {

  14.        int a,b;

  15.        while(cin >> a >> b)

  16.             cout << a+b << endl;
  17.        return 0;

阅读(2083) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~