Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

My is also wrong

Posted by LoveW at 2007-04-15 19:30:23 on Problem 1787
In Reply To:修改过的代码,还是WA,无奈中^^^^^^ Posted by:jackie_wyx at 2006-12-08 16:53:55
#include <stdio.h>

main()
{
  int d[6]={0,1,5,10,25,0};
  int a[6],b[6],e[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)
  {
    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--)
      {
        if(a[i]>0)
        {
          p=0;
          while(p==0 && a[i]>0)
          {
            p=d[i];
            for(j=1;j<i;j++)
            {
              b[j]=0;
              e[j]=c[j];
            }
            for(j=i-1;j>=1;j--)
            {
              while(p>=d[j] && e[j]>0)
              {
                e[j]--;
                b[j]++;
                p=p-d[j];
              }
            }
            if(p==0)
            {
              a[i]--;
              c[i]++;
              for(j=1;j<i;j++)
              {
                a[j]+=b[j];
                c[j]=e[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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator