acm_step1.1.4
2017-06-18 15:29
369 查看
题目描述:
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
题意:输入N,表示将要计算n个数的和,若n为0,则不作任何处理。
难点:对i从0到n-1时的处理,不太容易计算每次输入的和,容易忽略每次加后,对sum置0.
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
题意:输入N,表示将要计算n个数的和,若n为0,则不作任何处理。
#include<stdio.h> int main() { int n, a, i; int sum = 0; while (scanf("%d", &n) != EOF) { if (n != 0) { for (i = 0; i < n; i++) /*从0开始输入n个数*/ { scanf("%d", &a); sum += a; /*每次输入后都把值加到sum上*/ } printf("%d\n", sum); sum = 0; /*每次结束后都把sum重置为0*/ } } return 0; }
难点:对i从0到n-1时的处理,不太容易计算每次输入的和,容易忽略每次加后,对sum置0.
相关文章推荐
- ACM STEP 1.1.4 A+B for Input-Output Practice (IV)
- ACM训练计划step 1 [非原创]
- HDU ACM Step 2.1.5 找新朋友(欧拉函数)
- ACMSTEP 1.2.8 AC me! //水题 模拟题
- ACMSTEP 1.3.5 排序//排序 字符串
- ACMSTEP 3.1.5 统计问题 //递推
- acm_step1.1.5
- ACM训练计划step 2 [非原创]
- Acm Step Chapter One Section Two—Rightmost Digit
- ACMSTEP 2.1.7 Leftmost Digit // 数论 求 N^N最高次位
- ACMSTEP 3.1.4 Tiling_easy version //递推
- ACM STEP 1.1.5A+B for Input-Output Practice (V)
- acm_step1.1.6 1.1.7 1.1.8
- 邝斌的ACM模板(Baby-Step Giant-Step)
- HDU ACMstep1.2.8 Vowel counting
- ACM STEP 1.1.6 A+B for Input-Output Practice (VI)
- HDU--ACMstep--Wooden Sticks
- 杭电 acm step 1.3.7 As Easy As A+B
- C、C++输出精度控制—hdu acmstep 1.2.4 financial management&&1.2.8 balloon comes
- ACMSTEP 1.2.5 IBM Minus One//超级水题