giabinh

10226_HardwoodSpecies

Aug 20th, 2015
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define fto(i, l, r) for (int i=l; i<=r; ++i)
  4.  
  5. using namespace std;
  6.  
  7. string s;
  8. int test, all;
  9. map <string, int> trees;
  10.  
  11. int main () {
  12.     #ifndef ONLINE_JUDGE
  13.         freopen("uva10226.inp", "r", stdin);
  14.     #endif // OLINE_JUDGE
  15.  
  16.     scanf("%d", &test);
  17.     getline(cin, s); getline(cin, s);
  18.     while (test--)
  19.     {
  20.         trees.clear(); all = 0;
  21.         while (1)
  22.         {
  23.             getline(cin, s);
  24.             if (s.length() == 0) break; //cout << s << " ";
  25.             ++all; //cout << all;
  26.             if (!trees[s]) trees[s] = 1; else ++trees[s];
  27.         }
  28.  
  29.         for (map <string, int> :: iterator it = trees.begin(); it != trees.end(); it++)
  30.         {
  31.             float tmp = (float) (*it).second / all * 100;
  32.             cout << (*it).first;
  33.             printf(" %.4f\n", tmp);
  34.         }
  35.  
  36.         if (test > 0) printf("\n");
  37.     }
  38.  
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment