- #include <iostream>
- #include <string>
- #include <sstream>
- #include <stdio.h>
- #include <ctype.h>
- #include <algorithm>
- #include <cmath>
- using namespace std;
- int main() {
- // Problem 2. 找錢問題
- string N;
- getline(cin, N);
- int n = stoi(N);
- string input;
- for(int i = 0;i < n;i++)
- {
- getline(cin, input);
- stringstream ss(input);
- string token;
- int product[3];
- int c = 0;
- while (getline(ss, token, ','))
- {
- product[c] = stoi(token);
- c++;
- }
- int change;
- if(product[1] == 1)
- {
- change = product[0] - 17*product[2];
- }
- else if(product[1] == 2)
- {
- change = product[0] - 25*product[2];
- }
- int coin[4] = {1, 5, 10, 50};
- int chan[4];
- fill(chan, chan+4, 0);
- chan[3] = floor(change/50);
- chan[2] = floor((change%50)/10);
- chan[1] = floor((change%50%10)/5);
- chan[0] = floor((change%50%10%5)/1);
- int sp = 0;
- for(int j = 0;j < 4;j++)
- {
- if(chan[j] != 0)
- {
- if(sp != 0)
- {
- cout << ",Coin " << coin[j] << ":" << chan[j];
- }
- else
- {
- cout << "Coin " << coin[j] << ":" << chan[j];
- sp++;
- }
- }
- }
- cout << endl;
- }
- return 0;
- }
2018年1月12日 星期五
[ITSA Exam.61] Problem 2. 找錢問題
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言