Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <iomanip>
- using namespace std;
- class table{
- private:
- char ch;
- int cents;
- public:
- table(): ch(0), cents(0) {}
- char getchar() { return ch;}
- int getcents() { return cents;}
- void read() {
- cin >> ch;
- cin >> cents;
- }
- };
- int findchar(table *T, int K, char ch){
- for (int i = 0; i < K; i++){
- if (T[i].getchar() == ch)
- return T[i].getcents();
- }
- return 0;
- }
- int main(){
- cout.setf(ios::fixed);
- string str;
- int pay, N, M, K;
- double payment;
- cin >> N;
- while (N--){
- pay = 0;
- payment = 0;
- cin >> K;
- table t[K];
- for (int i = 0; i < K; i++)
- t[i].read();
- cin >> M;
- for (int i = 0; i < M; i++){
- cin.sync();
- getline(cin, str);
- for (int j = 0; str[j]; j++)
- pay += findchar(&t[0], K, str[j]);
- }
- payment = pay / 100.0;
- cout << setprecision(2) << payment << "$" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement