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 |
Why i was always wrong ?I've checked quite a lot of test cases, but I still haven't found a wrong answer.My code is as follow: #include <iostream> using namespace std; int c1,c2,c3,c4; void print() { printf("Throw in %d cents, %d nickels, %d dimes, and %d quarters.\n",c1,c2,c3,c4); } int main() { long int price,sum,del; cin >> price >> c1 >> c2 >> c3 >> c4; while(price || c1 || c2 || c3 || c4) { sum = c1 + 5*c2 + 10*c3 + 25*c4; price = sum - price; if(price<0) cout << "Charlie cannot buy coffee.\n"; else //subtract the least coins. { if(!price) { print(); goto in; } else { del = (price/25)>c4?c4:(price/25); c4 -= del; price -= 25*del; } if(!price) { print(); goto in; } else { del = (price/10)>c3?c3:(price/10); c3 -= del; price -= 10*del; } if(!price) { print(); goto in ; } else { del = (price/5)>c2?c2:(price/5); c2 -= del; price -= 5*del; } if(!price) { print(); goto in; } else { del = price>c1?c1:price; c1 -= del; price -= del; } if(!price) print(); else cout << "Charlie cannot buy coffee.\n"; } in: cin >> price >> c1 >> c2 >> c3 >> c4; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator