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 |
帮看看哪里有问题, 贪心调整不正确么?#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator