标题:[求助]这个题结果对,但是提交错误,怎么回事啊
只看楼主
liewmn
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2007-9-19
 问题点数:0 回复次数:2 
[求助]这个题结果对,但是提交错误,怎么回事啊

这是我的代码
#include<stdio.h>
int main()
{
int i,a[10000],b[10000];
for(i=1;i<=10;i++)
{
scanf("%d",&a[i]);
if(a[i]==0)
break;
}
for(int k=1;k<i;k++)
b[k]=a[k];
for(int j=1;j<=i-1;j++)
{
if((b[j]-6)%4==0)
{
printf("%d is the sum of four consecutive integers.\n",b[j]); }
else
{
printf("%d]is not the sum of four consecutive integers.\n",b[j]); }

}
return 1;
}
这是题目
Input
A positive integer(<231), each case will be on a separate line. A zero (0) denotes the end of input.
Output
The phrase “ is not the sum of four consecutive integers.” or the phrase “ is the sum of four consecutive integers.”, where is the number in question.
Example
In this example, 2 = -1 + 0 + 1 + 2, and 82 = 19 + 20 + 21 + 22. 5 and 41 are not of the correct form.
Input
5
41
82
0
Output
2 is the sum of four consecutive integers.
5 is not the sum of four consecutive integers.
41 is not the sum of four consecutive integers.
82 is the sum of four consecutive integers.

搜索更多相关主题的帖子: 结果 int main include 
2007-10-11 23:28
永夜的极光
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:2721
专家分:1
注 册:2007-10-9
得分:0 
1、A zero (0) denotes the end of input.你忘记看这句了

2、2的31次方超过int的范围了,用long类型(long的范围多少我也不记得了,或者应该用无符号的long)

3、何必从数组a复制到b呢?

4、判断的话用a[i]%4==2判断就好了

从BFS(Breadth First Study)到DFS(Depth First Study)
2007-10-12 13:29
leeco
Rank: 4
等 级:贵宾
威 望:10
帖 子:1026
专家分:177
注 册:2007-5-10
得分:0 


#include <stdio.h>
char* str[]={\" is not the sum of four consecutive integers.\",
\" is the sum of four consecutive integers.\"};
int main()
{
int n;
while(scanf(\"%d\",&n),n){
printf(\"%d%s\n\",n,str[n%4==2]);
}
}

2007-10-12 21:21



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-176916-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.192259 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved