joj 1877

按这题目来就行

 

 

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
struct node{
    char name[35];
    int total_num;
};
node tree[10001];
int main()
{
    int len=0,num=0;
    char str[35];
    while(gets(str))
    {
       if(strcmp(str,"")==0)
       {
           int i;
           for(i=num-1;i>=0;i--)
           {
              printf("%s %.4lf\n",tree[i].name,double(tree[i].total_num)/len*100);
           }
           printf("\n");
           len=0;
           num=0;
           continue;
       }
       int i;
       if(len==0)
       {
          len++;
          strcpy(tree[0].name,str);
          tree[0].total_num=1;
          num++;
          continue;
       }
       for(i=0;i<len;i++)
       {

          if(strcmp(tree[i].name,str)==0)
          {
               tree[i].total_num++;
               break;
          }
          else if(strcmp(tree[i].name,str)>0)
          {
               ;
          }
          else
          {
               num++;
               int j;
               for(j=len;j>i;j--)
               {
                   strcpy(tree[j].name,tree[j-1].name);
                   tree[j].total_num=tree[j-1].total_num;

               }
               strcpy(tree[i].name,str);
               tree[i].total_num=1;
               break;
          }
       }
       if(i==len)
       {
          strcpy(tree[i].name,str);
          tree[i].total_num=1;
          num++;
       }
       len++;
    }
    int i;
    for(i=num-1;i>=0;i--)
    {
       printf("%s %.4lf\n",tree[i].name,double(tree[i].total_num)/len*100);
    }
}

 

posted @ 2012-02-14 15:12  DChipNau  阅读(212)  评论(0编辑  收藏  举报