Presentation Error

来源:百度知道 编辑:UC知道 时间:2024/09/28 12:34:59
Problem 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.

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

Sample Output
10

15

6

我的解答

#include <stdio.h>
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int i,n,s,a;
scanf("%d",&n);
s=0;
for(i=1;i<=n;i++)
{
scanf("%d",&a);
s=s+a;
}
printf("%d\n\n",s);
}
return 0;
}

哪里有问题 谢谢

there is a blank line between outputs

而你每行后面都输出空行了,所以PE

可以添加个标记,只要不是第一组数据,就先输出个空行再输结构就可以了,代码如下

#include <stdio.h>
int main()
{
int T;
int flag; //这里
flag=0;
scanf("%d",&T);
while(T--)
{
int i,n,s,a;
scanf("%d",&n);
s=0;
for(i=1;i<=n;i++)
{
scanf("%d",&a);
s=s+a;
}
if(flag)
printf("\n");
else
flag=1;
printf("%d\n",s);
}
return 0;
}