// UVa 10226 - Hardwood Species
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;
struct par {
string s;
int i;
};
bool operator <(const par & a, const par & b) {
return a.s < b.s;
}
int main() {
int cases;
cin >> cases;
string line;
getline(cin, line);
getline(cin, line);
for (; cases; cases--) {
map<string, int> m;
int n = 0;
getline(cin, line);
while (line.length() > 0) {
m[line]++;
n++;
getline(cin, line);
}
vector<par> v;
for (map<string, int>::const_iterator I = m.begin(); I != m.end(); I++) {
par p = { I->first, I->second };
v.push_back(p);
}
sort(v.begin(), v.end());
for (int i = 0; i < v.size(); i++) {
double per = v[i].i * 100.0 / n;
cout << v[i].s << " ";
printf("%.4f", per);
cout << endl;
}
if (cases > 1)
cout << endl;
}
return 0;
}
Monday, June 22, 2015
UVa 10226 - Hardwood Species
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment