2013
11-27

# A+B for Input-Output Practice (VIII)

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.

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.

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

10

15

6

2011-12-14 05:16:49

# include <stdio.h>

int main ()
{
int sum, n, num ;
int flag = 0 ;
scanf ("%d", &n) ;
while (~scanf ("%d", &n))
{
sum = 0 ;
while (n--){
scanf ("%d", &num) ;
sum += num ;
}
if (flag == 0) flag = 1 ;
else puts ("") ;
printf ("%d\n", sum) ;
}
return 0 ;
}

1. 约瑟夫也用说这么长……很成熟的一个问题了，分治的方法解起来o(n)就可以了，有兴趣可以看看具体数学的第一章，关于约瑟夫问题推导出了一系列的结论，很漂亮