ACM——A + B Problem (4)

A + B Problem (4)

时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte
总提交:2496            测试通过:1249

描述

Calculate the sum of some integers.

输入

The input will consist of multiple test cases. Each test case consist of an integer N and then N integers following in the same line,separated by a space. A line starting with 0 terminates the input and this line is not to be processed.

输出

For test case, you should output their sum in one line, and with one line of output for each line in input. After each test case output, you should output one blank line.

样例输入

4 1 2 3 4
5 1 2 3 4 5
0

样例输出

10

15

题目来源

HDUOJ

 

#include<iostream>
#include<vector>
using namespace std;
int main(){
    int i,a,b;
    vector<int> ivec;
    int sum=0;
    while(cin>>a)
    {
        if(a==0)
            break;
        for(i=0;i<a;i++)
        {
            cin>>b;
            sum+=b;
        }
        ivec.push_back(sum);
        sum=0;
    }
    for(i=0;i<ivec.size();i++)
        cout<<ivec[i]<<endl<<endl;
    return 0;
}

 

 

 

转载于:https://www.cnblogs.com/BasilLee/p/3791831.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值