fork(3) download
  1. /**
  2.  *
  3.  * UVa 10226 - Hardwood Species
  4.  *
  5.  * I encourage you to use this code only as a reference. And remember the
  6.  * 100% rule if you plan to use the input-reading method included here.
  7.  *
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <map>
  12. #include <string>
  13.  
  14. using namespace std;
  15.  
  16. int main(){
  17. int TC,tot;
  18. double p;
  19. string name;
  20. char str[31];
  21. scanf("%d ",&TC);
  22.  
  23. for (int k = 0; k < TC; ++k){
  24. if (k > 0) putchar('\n');
  25. map<string,int> m;
  26.  
  27. tot=0;
  28. while(scanf("%30[^\n]%*c",str)==1){
  29. m[str]++;
  30. tot++;
  31. }
  32. scanf(" ");
  33. for(map<string,int>::iterator it=m.begin();it!=m.end();it++){
  34. p=(100*(double)(it->second))/tot;
  35. printf("%s %0.4lf\n",(it->first).c_str(),p);
  36. }
  37. }
  38. return 0;
  39. }
Success #stdin #stdout 0s 3480KB
stdin
2

ABC
DEF
ABC
DEF

ZZZZZ
ZZZZ
ZZZ
stdout
ABC 50.0000
DEF 50.0000

ZZZ 33.3333
ZZZZ 33.3333
ZZZZZ 33.3333