A+B for Input-Output Practice (I)

A+B for Input-Output Practice (I)

时间: 1ms        内存:64M

描述:

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

输入:

The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.

输出:

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.

示例输入:

1 5
10 20

示例输出:

6
30

提示:

参考答案(内存最优[748]):

#include<stdio.h>
void main()
{
	int a[100],b[100],c[100];
	int i,n;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d",&a[i],&b[i]);
		c[i]=a[i]+b[i];
	}
	for(i=0;i<n;i++)
		printf("%d\n",c[i]);
}

参考答案(时间最优[0]):

#include <stdio.h>
#include <stdlib.h>
int main()
{
  int a,b;
 while(scanf("%d %d",&a, &b) != EOF)
 printf("%d\n",a+b);	
  return 0;
}

题目和答案均来自于互联网,仅供参考,如有问题请联系管理员修改或删除。

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注