UVa 10226 - Hardwood Species

  题目大意:给出n棵树(有重复),统计每种树出现的频率。使用STL的map。

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <map>
 4 #include <string>
 5 #include <iomanip>
 6 #include <algorithm>
 7 using namespace std;
 8 typedef map<string, int> msi;
 9 
10 int main()
11 {
12 #ifdef LOCAL
13     freopen("in", "r", stdin);
14 #endif
15     int T;
16     scanf("%d", &T);
17     getchar();
18     string str;
19     getline(cin, str);
20     msi m;
21     while (T--)
22     {
23         int total = 0;
24         m.clear();
25         while (getline(cin, str))
26         {
27             if (str[0] == 0)  break;
28             total++;
29             m[str]++;
30         }
31         for (msi::iterator it = m.begin(); it != m.end(); it++)
32             cout << it->first << " " << fixed << setprecision(4) << it->second * 100.0 / total << endl;
33         if (T)  printf("\n");
34     }
35     return 0;
36 }
View Code

  这个也是总是Submission error,结果未知...

posted @ 2013-09-01 12:34  xiaobaibuhei  阅读(547)  评论(0编辑  收藏  举报