1008: A+B for Input-Output Practice (VIII)

矫情吗;* 2023-01-10 01:23 96阅读 0赞

Description

Your task is to calculate the sum of some integers.

Input

Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.

Output

For each group of input integers you should output their sum in one line, and you must note that there is a blank line between outputs.

" class="reference-link">Sample Input 5f8f312f51791b8bb0ed0ae07c2ffa43.gif

  1. 3
  2. 4 1 2 3 4
  3. 5 1 2 3 4 5
  4. 3 1 2 3

Sample Output

  1. 10
  2. 15
  3. 6

Code

  1. #include<stdio.h>
  2. #include<iostream>
  3. using namespace std;
  4. int main()
  5. {
  6. int n;
  7. cin>>n;
  8. while(n--)
  9. {
  10. int a;
  11. cin>>a;
  12. int s[a];
  13. int ans=0;
  14. while(a--)
  15. {
  16. cin>>s[a];
  17. ans+=s[a];
  18. }
  19. cout<<ans<<endl<<endl;
  20. }
  21. return 0;
  22. }

发表评论

表情:
评论列表 (有 0 条评论,96人围观)

还没有评论,来说两句吧...

相关阅读