| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
修改过的代码,还是WA,无奈中^^^^^^In Reply To:哪位给兄弟些测试数据啊?无奈中^^^^^^ Posted by:jackie_wyx at 2006-12-08 14:58:58 #include <stdio.h>
main()
{
int d[6]={0,1,5,10,25,0};
int a[6],c[6];
int p,i,j,sum;
scanf("%d%d%d%d%d",&p,&c[1],&c[2],&c[3],&c[4]);
while(p!=0 || c[1]!=0 || c[2]!=0 || c[3]!=0 || c[4]!=0)
{
for(i=1;i<=4;i++) a[i]=0;
for(i=4;i>=1;i--)
{
while(p>=d[i] && c[i]>0)
{
c[i]--;
a[i]++;
p=p-d[i];
}
}
if(p!=0) printf("Charlie cannot buy coffee.\n");
else
{
for(i=4;i>1;i--)
{
sum=0;
for(j=1;j<i;j++) sum+=c[j]*d[j];
while(sum>d[i] && a[i]>0)
{
a[i]--;
c[i]++;
sum-=d[i];
p=d[i];
for(j=i-1;j>0;j--)
{
while(p>=d[j] && c[j]>0)
{
c[j]--;
a[j]++;
p=p-d[j];
}
}
}
}
printf("Throw in %d cents, %d nickels, %d dimes, and %d quarters.\n",a[1],a[2],a[3],a[4]);
}
scanf("%d%d%d%d%d",&p,&c[1],&c[2],&c[3],&c[4]);
}
return(0);
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator