C语言问题,为什么会显示Runtime Error

AfterShawnseesthefollowingpicture,hedecidestogiveuphiscareerinITandturntosellfruits.S... AfterShawn sees the following picture, he decides to give up his career in IT andturn to sell fruits. Since Shawn is a lazy guy, he doesn’t like to do any extrawork. When he starts selling fruits, he finds that he always needs to takechanges for customers. He wants you to write a program to give the least numberof changes. Shawn is also a strange guy, because he takes changes by 6,5,3,1.

Input
Thefirst line of input is an integer T which indicates the sum of test case. Eachof the following T lines contains an integer n(1≤n≤105), which isthe total money Shawn need to give to the customer.

Output
Foreach test case, output "Case i: Result" in one line whereiis the case number andResultis the least number of changes Shawnneed to give customer.

SampleInput
3
4
10
19

Sampleoutput
Case 1: 2
Case 2: 2
Case 3: 4

下面是我的:

#include <stdio.h>

int main()
{
int i,j,a[10],s;
scanf("%d",&j);
for(i=0;i<j;i++)
{
scanf("%d",&a[i]);
}

for(i=0;i<j;i++)
{
if(a[i]%5==0)
s=a[i]/5;
else
s=a[i]/6+(a[i]%6)/5+((a[i]%6)%5)/3+((a[i]%6)%5)%3;

printf("Case %d: %d\n",i+1,s);
}

return 0;
}
展开
 我来答
百度网友6fe74e2
2013-05-11 · TA获得超过6593个赞
知道大有可为答主
回答量:1973
采纳率:100%
帮助的人:260万
展开全部

应该是没有什么问题啊

更多追问追答
追问

对啊,没问题啊,但是提交到ACM网址的那里,显示的是

搞的我很恼火。。三小时就只琢磨这一道题了

追答
ACM的题,嗯,我详细看了下,
如果你的j大于10时,程序的确是runtime error的,这个问题只能用动态内存分配来做:
#include "stdio.h"
#include "stdlib.h"
int main()
{
int i,j,s;
int *a=NULL;
scanf("%d",&j);
a=(int *)malloc(sizeof(int)*j);
for(i=0;i<j;i++)
{
scanf("%d",a+i);
}

for(i=0;i<j;i++)
{
if(a[i]%5==0)
s=a[i]/5;
else
s=a[i]/6+(a[i]%6)/5+((a[i]%6)%5)/3+((a[i]%6)%5)%3;

printf("Case %d: %d\n",i+1,s);
}
free(a);
a=NULL;
return 0;

}
这样才是最对的做法,你可以用这个去提交
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式