題目:
https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=14&page=show_problem&problem=1167
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| #include <iostream> #include <iomanip> #include <map> #include <vector>
using namespace std;
int main(){ ios::sync_with_stdio(0); cin.tie(0);
int cases; cin >> cases; cin.ignore(); cin.ignore(); for(int t=0; t<cases; ++t){ map<string, int> m; string text; vector<string> woods; int total = 0; while(getline(cin, text)){ if(text.empty()) break; ++m[text]; ++total; } for(auto &p : m){ cout << p.first << ' ' << fixed << setprecision(4) << double(p.second)/double(total)*100 << '\n'; } if(t != cases-1) cout << '\n'; } return 0; }
|