Time Limit: 10000MS | Memory Limit: 65536K | |
Total Submissions: 20085 | Accepted: 7911 |
Description
Input
Output
Sample Input
Red Alder Ash Aspen Basswood Ash Beech Yellow Birch Ash Cherry Cottonwood Ash Cypress Red Elm Gum Hackberry White Oak Hickory Pecan Hard Maple White Oak Soft Maple Red Oak Red Oak White Oak Poplan Sassafras Sycamore Black Walnut Willow
Sample Output
Ash 13.7931 Aspen 3.4483 Basswood 3.4483 Beech 3.4483 Black Walnut 3.4483 Cherry 3.4483 Cottonwood 3.4483 Cypress 3.4483 Gum 3.4483 Hackberry 3.4483 Hard Maple 3.4483 Hickory 3.4483 Pecan 3.4483 Poplan 3.4483 Red Alder 3.4483 Red Elm 3.4483 Red Oak 6.8966 Sassafras 3.4483 Soft Maple 3.4483 Sycamore 3.4483 White Oak 10.3448 Willow 3.4483 Yellow Birch 3.4483
Hint
#include <stdio.h> #include <stdlib.h> #include <string.h> const int maxn=127; //127叉树 typedef struct Node{ int cnt; struct Node *ch[maxn]; }node; node *T; int tot; void insert(char s[]){ int i,j,len=strlen(s); node *u; u=T; for(i=0;i<len;i++){ int id=s[i]; if(u->ch[id]==0){ node *t=(node*)malloc(sizeof(node)); for(j=0;j<maxn;j++) t->ch[j]=0; t->cnt=0; u->ch[id]=t; } u=u->ch[id]; } u->cnt++; } char name[40]; void ask(node* T,int cur){ if(T==0) return ; int i; double res; if(T->cnt) { name[cur]='\0'; res=(double)T->cnt/tot*100; printf("%s %.4f\n",name,res); } for(i=0;i<maxn;i++) if(T->ch[i]!=0){ name[cur]=i; ask(T->ch[i],cur+1); } return ; } int main() { int i,res,len; char str[40]; T=(node*)malloc(sizeof(node)); for(i=0;i<maxn;i++) T->ch[i]=0; T->cnt=0; tot=0; while(gets(str)){ if(str[0]=='\0') break; insert(str); tot++; } ask(T,0); return 0; }
#include <iostream> #include <cstdio> #include <iterator> #include <map> #include <string> using namespace std; int main() { string str; int tot=0; map<string,int> mp; while(getline(cin,str)){ mp[str]++; tot++; } map<string,int>::iterator it; for(it=mp.begin();it!=mp.end();it++){ cout<<it->first; printf(" %.4f\n",(double)it->second/tot*100); } return 0; }