UVa 10226 - Hardwood Species
题目大意:给出n棵树(有重复),统计每种树出现的频率。使用STL的map。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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 }
这个也是总是Submission error,结果未知...