Skip to content

Instantly share code, notes, and snippets.

@dudelson
Created January 7, 2017 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dudelson/894680bf115ca1e853c9508b40dc7a1d to your computer and use it in GitHub Desktop.
Save dudelson/894680bf115ca1e853c9508b40dc7a1d to your computer and use it in GitHub Desktop.
My solution for UVA 10226
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
using namespace std;
map<string, int> m;
int n;
double trees;
string s;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n; getline(cin, s); getline(cin, s);
cout << setprecision(4) << fixed;
for(int i=0; i<n; i++) {
if(i > 0) cout << '\n';
trees = 0;
m.clear();
while(getline(cin, s) && s!="") {
m[s]++;
trees++;
}
for(map<string, int>::iterator it=m.begin(); it!=m.end(); it++)
cout << it->first << " " << (it->second)*100/trees << '\n';
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment