案例4-1.6 树种统计 (25 分)
简答题,利用map
#include<iostream>
#include<map>
#include<string>
#include<cstdio>
using namespace std;
map<string,int> m;
int main()
{
int n,i;
cin>>n;
string a;
i=n;
cin.get();
while(i--){
getline(cin,a);
m[a]++;
}
map<string,int>::iterator it;
for(it=m.begin();it!=m.end();it++)
{
cout<<it->first<<" ";
printf("%.4lf%%\n",(it->second)*100.0/n);
}
return 0;
}