Advertisement
MiinaMagdy

11340 - Newspaper

Sep 7th, 2022
673
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll long long
  6. #define endl '\n'
  7. #define sz(x) int(x.size())
  8. #define all(x) x.begin(), x.end()
  9.  
  10. int main() {
  11.     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  12.     int test;
  13.     cin >> test;
  14.     while (test--) {
  15.         int n;
  16.         cin >> n;
  17.         char chars[n];
  18.         ll costs[n];
  19.         for (int i = 0; i < n; i++) {
  20.             cin >> chars[i] >> costs[i];
  21.         }
  22.         int m;
  23.         cin >> m;
  24.         string s;
  25.         ll total_price = 0;
  26.         cin.ignore();
  27.         for (int i = 0; i < m; i++) {
  28.             getline(cin, s);
  29.             for (int j = 0; j < sz(s); j++) {
  30.                 for (int k = 0; k < n; k++) {
  31.                     if (chars[k] == s[j]) total_price += costs[k];
  32.                 }
  33.             }
  34.         }
  35.         cout << fixed << setprecision(2) << total_price / 100.0 << '$' << endl;
  36.     }
  37. }
  38.  
Tags: UVA CP3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement