这题用标准STL做十分简单,但是时间有点长,我的程序如下:
Problem: 2418 | User: zhao999 | |
Memory: 440K | Time: 3063MS | |
Language: C++ | Result: Accepted |
- Source Code
#include <iostream> #include <map> #include<string> using namespace std; int count=0; int main () { map<string,int> mymap; map<string,int>::iterator it; string a; while(getline(cin,a)) { if(a.length()==0) break; mymap[a]++; count++; } for ( it=mymap.begin() ; it != mymap.end(); it++ ) { cout << (*it).first << " "; printf("%.4lf/n",100*(*it).second/(double)count); } return 0; }