giabinh

11340_Newspaper

Aug 22nd, 2015
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. map <char, float> table;
  6. int test, n, m;
  7. string s;
  8. float pays;
  9.  
  10. int main () {
  11.     #ifndef ONLINE_JUDGE
  12.         freopen("uva11340.inp", "r", stdin);
  13.     #endif // ONLINE_JUDGE
  14.  
  15.     scanf("%d", &test);
  16.     for (int itest = 0; itest<test; ++itest) {
  17.         scanf("%d", &n); getline(cin, s);
  18.         table.clear(); pays = 0.0;
  19.  
  20.         for (int i=0; i<n; ++i) {
  21.             char chara; float cents;
  22.             scanf("%c%f", &chara, &cents);
  23.             //cout << chara << " " << cents << endl;
  24.             table[chara] = cents; getline(cin, s);
  25.         }
  26.  
  27.         scanf("%d", &m); cin.ignore();
  28.         for (int i=0; i<m; ++i) {
  29.             getline(cin, s);
  30.             int len = s.length();
  31.             //cout << s << endl;
  32.  
  33.             for (int j=0; j<len; ++j) {
  34.                 if (table.find(s[j]) != table.end()) pays += table.find(s[j]) -> second;
  35.                 //cout << pays << " ";
  36.             }
  37.         }
  38.  
  39.         pays /= 100;
  40.         printf("%.2lf$\n", pays);
  41.     }
  42.  
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment