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

帮看看哪里有问题, 贪心调整不正确么?

Posted by wrong123 at 2005-12-29 00:49:16 on Problem 2581
#include<iostream>
#include<string>
using namespace std;

int main() {
    string s;
    int A,B,C,D,E,b,c,d,len,i;
    while(cin>>s>>B>>C>>D>>E){
        A=(s[0]-'0')*100+(s[2]-'0')*10+s[3]-'0';         //get integer value  
        b=c=d=0;

        //Greeding from big to small
        if(B*25 >= A){ 
            if(A%25==0){ cout<<A/25<<" 0 0 0"<<endl; continue;}
            b = A/25; A %= 25;
        }
        else { b=B; A -= b*25; }
        
        if(C*10 >= A){
            if(A%10==0){ cout<<b<<' '<<A/10<<" 0 0"<<endl; continue;}
            c = A/10; A %= 10;
        }
        else { c=C; A -= c*10; }
        
        if(D*5 >= A){
            if(A%5==0){ cout<<b<<' '<<c<<' '<<A/5<<" 0"<<endl; continue;}
            d = A/5; A %= 5;
        }
        else { d=D; A -= d*5; }
        
        if(E >= A) cout<<b<<' '<<c<<' '<<d<<' '<<A<<endl;        
        else cout<<"NO EXACT CHANGE"<<endl;        
    }
    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