c语言问题:杭电acm1096 麻烦告知一下哪里有问题,总是错误
题目*A+BforInput-OutputPractice(VIII)TimeLimit:2000/1000MS(Java/Others)MemoryLimit:6553...
题目
*A+B for Input-Output Practice (VIII)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 34086 Accepted Submission(s): 9957
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 i,a,b,c;
scanf("%d",&a);
for(i=0;i<a;i++)
{
while(scanf("%d",&b)==1)
{
for(i=1;i<=b;i++)
c+=b;
printf("%d\n\n",c);
}
return 0;
}
} 展开
*A+B for Input-Output Practice (VIII)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 34086 Accepted Submission(s): 9957
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 i,a,b,c;
scanf("%d",&a);
for(i=0;i<a;i++)
{
while(scanf("%d",&b)==1)
{
for(i=1;i<=b;i++)
c+=b;
printf("%d\n\n",c);
}
return 0;
}
} 展开
展开全部
#include<stdio.h>
int main()
{
int i,a,b,c;
scanf("%d",&a);
for(i=0;i<a;i++)
{
while(scanf("%d",&b)==1) //为什么要在循环里放循环?这个while完全多余。
{
for(i=1;i<=b;i++) //这里又是i变量,会导致外循环出错。
c+=b;
printf("%d\n\n",c); //你确定最后一行输出以后还有空行?acm的判断系统要求不差任何一个字符。
}
return 0;
}
}
int main()
{
int i,a,b,c;
scanf("%d",&a);
for(i=0;i<a;i++)
{
while(scanf("%d",&b)==1) //为什么要在循环里放循环?这个while完全多余。
{
for(i=1;i<=b;i++) //这里又是i变量,会导致外循环出错。
c+=b;
printf("%d\n\n",c); //你确定最后一行输出以后还有空行?acm的判断系统要求不差任何一个字符。
}
return 0;
}
}
科博尔
2024-10-31 广告
2024-10-31 广告
QT400-18是一种球墨铸铁材料,QT代表“球铁”,400表示其抗拉强度为400MPa,18则表示延伸率为18%。该材料属于铁素体型球墨铸铁,具有良好的韧性和塑性,能够承受高冲击振动及扭转等动、静载荷,特别在低温工作条件下具有较好的冲击性...
点击进入详情页
本回答由科博尔提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询