acm编程新手问题

来源:百度知道 编辑:UC知道 时间:2024/06/06 07:50:42
Problem Description
Your task is to Calculate the sum of some integers.

Input
Input contains multiple test cases. Each test case contains a integer N, and then N integers follow in the same line. A test case starting with 0 terminates the input and this test case is not to be processed.

Output
For each group of input integers you should output their sum 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
0

Sample Output
10
15

学校网站上的。
要用C或C++

好怀念ACM
你英文肯定没学好,这道题目很简单的;

main()
{
int a,b,c,i;
int sum;
while(scanf("%d",&a)!=0)
{
if(scanf("%d",&b)==0) conintue;
else
{
sum=0;
for(i=0;i<b;i++)
{scanf("%d",&c);
sum+=c;
}
printf("%d",sum);
}
}
}

因为题目没对整数大小限制,所以我用了INT

C++
include<iostream>
using namespace std;

int main()
{
int n,sum,k;
while(cin>>n)
{
if(n==0)
{
return 0;
}
sum=0;
while(n--)
{
cin>>k;
sum+=k;
}
cout<<sum<<endl;
}
return 0;
}
没编译过,你试试可不可以的

用Java写的:

import java.util.Scanner;
import java.util.Vector;

public class Baidu
{
static Scanner in = new Scanner(Sys