網頁

2014年2月5日 星期三

UVA 10226 - Hardwood Species

 #include <iostream>
 #include <cstdio>
 #include <iomanip>
 #include <string> 
 #include <map>
 #include <algorithm>
 
 using namespace std;
 
 int main(int argc, char *argv[]){
   int t;
   string line;
   cin >> t;
   getline(cin, line); // read new line
   getline(cin, line); // read new line
   while (t--){
     map<string, int> m;
     map<string, int>::iterator it;
     int count=0 ;
     while (getline(cin, line)){
       if (line=="") break;
       it = m.find(line);
       if (it == m.end()){
         m[line] = 1;
       } else {
         it->second++;
       }
       count++;
     }
     
     for (it=m.begin(); it!=m.end(); ++it){
       float percent = 100.0*it->second/count;
       cout  << it->first << ' ' << fixed << setprecision(4) << percent << endl;
     }
 
     if (t>0) cout << endl ;
     
   }
   return 0;
}

沒有留言:

張貼留言