A+B for Input-Output Practice (VI)

A+B for Input-Output Practice (VI)

时间: 1ms        内存:64M

描述:

Your task is to calculate the sum of some integers.

输入:

Input contains multiple test cases, and one case one line. Each case starts with an integer N, and then N integers follow in the same line.

输出:

For each test case you should output the sum of N integers in one line, and with one line of output for each line in input.

示例输入:

4 1 2 3 4
5 1 2 3 4 5

示例输出:

10
15

提示:

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

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

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

#include<iostream>
using namespace std;
int main()
{
	int N,sum,t;
	while(cin>>N){
		sum=0;
		while(N--){
			cin>>t;
			sum+=t;
		}
		cout<<sum<<endl;
	}
	return 0;
}

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

点赞

发表评论

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