秒过!一是以前做过,二是这题用map又水了。。唉~
#include <iostream> #include <map> #include <iomanip> #include <string> using namespace std; int main() { ios::sync_with_stdio(false); map<string, int> a; string name; int count = 0; while (getline(cin, name)) { ++a[name]; count++; } for (map<string, int>::const_iterator map_it = a.begin(); map_it != a.end(); ++map_it) { cout << map_it->first << ' ' << fixed << setprecision(4) << (map_it->second)*100.0 / count << endl; } } |