1135: 零起點學算法42——多組測試數據(求和)IV


1135: 零起點學算法42——多組測試數據(求和)IV

Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lld
Submitted: 2439  Accepted: 1277
[Submit][Status][Web Board]

Description

還有一些輸入是以上幾種情況的組合,具體根據題目對前面幾種情況進行組合
比如題目要求是多組測試數據
每組測試數據首先輸入一個整數n(如果n=0就表示結束) 然后再輸入n個整數
這類題目輸入格式如下:


int main()
{
int n,i;
while(scanf("%d",&n)!=EOF && n!=0)
{
for(i=1;i<=n;i++)
{
....//每次輸入一個數,共循環n次,需要的時候做其他處理
}

}
}

 

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

 

Source

 
 1 #include<stdio.h>
 2 int main(){
 3     int n;
 4     while(scanf("%d",&n)!=EOF&&n!=0){
 5         int a,s=0;
 6         for(int i=1;i<=n;i++){
 7             scanf("%d",&a);
 8             s+=a;
 9         }
10         printf("%d\n",s);
11     }
12     return 0;
13 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM