原题回顾
Problem Description
Your task is to calculate the sum of some integers.
Input
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.
Output
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.
Sample Input
4 1 2 3 4
5 1 2 3 4 5
Sample Output
10
15
这一道题和1092题几乎一样,答案如下:
#include <iostream>
#include<stdlib.h>
using namespace std;
int main()
{
int n,*a,sum=0;
while(cin>>n)
{
a=(int *)malloc(n*sizeof(int));
for(int i=0;i<n;i++)
{
cin>>a[i];
sum+=a[i];
}
cout << sum << endl;
sum=0;
}
return 0;
}
本文介绍了一种通过C++程序实现的整数求和方法,该程序能够接收多组输入数据,每组数据由一个整数N及随后的N个整数组成,并输出这些整数的总和。
435

被折叠的 条评论
为什么被折叠?



