[1003] A + B Problem

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[1003] A + B Problem相关的知识,希望对你有一定的参考价值。

1003: A+B Problem(4)

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 487  Solved: 242
[Submit][Status][Web Board]

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

[思路] 每组数前面有个组中的数字的个数,先读这个n,判断一下是不是0,后面的数就用一个for循环读进去累加起来就好。记得一开始的初始值要设0,不然会累加出来奇怪的东西。

[代码]

 1 #include <iostream>
 2 using namespace std;
 3  
 4 int main()
 5 {
 6     int n; 
 7     while(cin >> n && n) 
 8     {
 9         int sum = 0; int temp = 0;
10         for(int i = 0 ; i < n ; i++){cin >> temp ; sum += temp;}
11         cout << sum << endl;
12     }
13     return 0;
14 }

 

以上是关于[1003] A + B Problem的主要内容,如果未能解决你的问题,请参考以下文章

题目1003:A+B

1003.A+B

题目1003:A+B

SZTUOJ 1003.A+B(III)

用tensorflow学习贝叶斯个性化排序(BPR)

杭电OJ 1003