zoukankan      html  css  js  c++  java
  • 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);
        }
    }

  • 相关阅读:
    使用网络服务
    Linux Socket 学习(九)
    Linux Socket学习(六)
    Linux Socket学习(八)
    Developing Software in Visual Studio .NET with NonAdministrative Privileges
    html5+css3实现一款注册表单
    linux编程下signal()函数
    深入理解Oracle索引(10):索引列字符类型统计信息的32位限制
    智能手机屏幕清晰度用户体现的分析:PPI与PPI2
    架设邮件服务器windows 2003 POP3服务,SMTP服务收发邮件
  • 原文地址:https://www.cnblogs.com/dchipnau/p/4985932.html
Copyright © 2011-2022 走看看