ACM简单的A+B问题

烧把火 2011-09-09 04:55:06
Problem Description :Your task is to Calculate the sum of some integers.



Input: Input contains multiple test cases. Each test case contains a integer N, and then N integers follow in the same line. A test case starting with 0 terminates the input and this test case is not to be processed.



Output: For each group of input integers you should output their sum in one line, and with one line of output for each line in input.

代码:
#include <stdio.h>
#include <iostream>
int main()
{
int a,b,i,s=0;
while(scanf("%d",&a) &&(a!=0))
{
for(i=0;i<a;i++)
{scanf("%d",&b); s+=b;}
printf("%d\n",s);
}
}
为什么提示wrong answer
...全文
528 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
烧把火 2011-09-11
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ulfsaar 的回复:]
要放到While里

C/C++ code

#include <stdio.h>
int main()
{
int a,b,i,s;
while(scanf("%d",&a) && (a!=0) )
{
s =0;
for(i=0;i<a;i++)
{
……
[/Quote]
这回终于Accept了 谢谢啊
尘缘udbwcso 2011-09-10
  • 打赏
  • 举报
回复

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

life_at_606 2011-09-10
  • 打赏
  • 举报
回复
代码没有问题,我已经运行过了,可能是LZ编译器出了小差错,么么哒
Ulfsaar 2011-09-09
  • 打赏
  • 举报
回复
s=0;
要放到While里
Ulfsaar 2011-09-09
  • 打赏
  • 举报
回复
要放到While里

#include <stdio.h>
int main()
{
int a,b,i,s;
while(scanf("%d",&a) && (a!=0) )
{
s =0;
for(i=0;i<a;i++)
{
scanf("%d",&b);
s+=b;
}

printf("%d\n",s);
}
}
s=0;

never517 2011-09-09
  • 打赏
  • 举报
回复
我把代码跑了下,ok的,哪有wrong answer ?

65,186

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧