poj2418

用map,c++就可以过

View Code
#include <iostream>
#include
<cstdio>
#include
<cstdlib>
#include
<cstring>
#include
<map>
#include
<algorithm>
using namespace std;
#include
<string>

#define maxn 1000005

map
<string, int> tree;
string st, name[maxn];
int ncount = 0, tot = 0;

int main()
{
//freopen("t.txt", "r", stdin);

while (getline(cin, st) && !(st == ""))
{
if (tree.find(st) == tree.end())
{
tree[st]
= 1;
name[ncount
++] = st;
}
else
tree[st]
++;
tot
++;
}
sort(name, name
+ ncount);
for (int i = 0; i < ncount; i++)
printf(
"%s %.4f\n", name[i].c_str(), tree[name[i]] * 1.0 / tot * 100);
return 0;
}

posted @ 2011-05-21 16:21  金海峰  阅读(566)  评论(0编辑  收藏  举报