A+B for Input-Output Practice (VIII)

emmm,经典题目的最后一题,当年却费了些周折,因为太菜了,自己读程读了半天才发现,还是有些小陷阱的,还是先审题。 emmm,经典题目的最后一题,当年却费了些周折,因为太菜了,自己读程读了半天才发现,还是有些小陷阱的,还是先审题。
Problem Description Problem Description
Your task is to calculate the sum of some integers.
Your task is to calculate the sum of some integers.

Input 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.
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 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.
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.

Sample Input Sample Input
3
4 1 2 3 4
5 1 2 3 4 5
3 1 2 3
3 4 1 2 3 4 5 1 2 3 4 5 3 1 2 3

Sample Output Sample Output
10

15

6
10 15 6

Author Author
lcy lcy
看完题目,不少初学者与当年的我一样,肯定十分激动,天啊,这与练习五好像啊,只不过输出变了,立马把当时的代码翻出来,改了一下,就submit了。最后却只有失望的橙黄色,那么问题出在哪呢? 看完题目,不少初学者与当年的我一样,肯定十分激动,天啊,这与练习五好像啊,只不过输出变了,立马把当时的代码翻出来,改了一下,就submit了。最后却只有失望的橙黄色,那么问题出在哪呢?
从输出不难看出,最后一个后应该没有空格,那么问题就来了,如果n=1,那么之和即是第一个又是最后一个,那肯定是不需要空格的,这就需要我们分情况讨论。现在上代码: 从输出不难看出,最后一个后应该没有空格,那么问题就来了,如果n=1,那么之和即是第一个又是最后一个,那肯定是不需要空格的,这就需要我们分情况讨论。现在上代码:
#include<stdio.h>
int main()
{
	int i,j,k,n,a,sum;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		    scanf("%d",&j);
			sum=0;
			for(k=0;k<j;k++)
			{
				scanf("%d",&a);
				sum+=a;
			}
			if(n==1)
			{
				printf("%d
",sum);
			}
			else
			{
				printf("%d

",sum);
			}	
	}
	return 0;
}
其实我当时犯的错误还不止这些(还是太菜了),那么入门就写到这里,下面会写些做过的水题和才研究的新题,希望能与大家交流进步吧。

#include int main() { int i,j,k,n,a,sum; scanf("%d",&n); for(i=0;i
经验分享 程序员 微信小程序 职场和发展