zoukankan      html  css  js  c++  java
  • hdu 2093 考试排名

    http://acm.hdu.edu.cn/showproblem.php?pid=2093

    这道题目昨天做到今天啦,总算ac了,这道题目其实不难,只是有点麻烦,先按做的数目排序,然后再按和从小到大排序,最后还要按字典序排序,最后还有格式的控制,其实处理括号的时可以用sscanf(字符串首地址(不用引号),"%d(%d)",&a,&b),它返回的是输入数据的个数,其实sscanf与scanf的区别就是前者是已经输入的字符串中读入,后者是从键盘输入,返回的都是输入的个数

    下面是没有用sscanf的代码:

    #include <stdio.h>

    #include <string.h>

    #include <stdlib.h>

    #include <math.h>

    struct  edg

    {

            char s[100];

            int sum,ac,flag;

    }e[10000];

    int cmp(const void *a,const void *b)

    {

         if(((struct edg *)a)->flag!=((struct edg *)b)->flag)

         return ((struct edg *)b)->flag-((struct edg *)a)->flag;

         else 

         {

                    if(((struct edg *)a)->sum!=((struct edg *)b)->sum)

                    return ((struct edg *)a)->sum-((struct edg *)b)->sum;

                    else

                    return strcmp(((struct edg *)a)->s,((struct edg *)b)->s);

         } 

        

    }

    int main()

    {

        int n,m,i=0;

        char t[100];

        scanf("%d%d",&n,&m);

        while(scanf("%s",e[i].s)!=EOF)

        {

                int a,b;

                e[i].sum=e[i].ac=e[i].flag=0;

                for(int j=0;j<n;++j)

                {

                        int max=0;

                        a=0;b=0;

                        scanf("%s",t);

                        int c=strlen(t);

                        if(t[0]=='-'||!(t[0]-'0'))  continue;

                        else 

                        {

                             e[i].flag++;

                             if(t[c-1]==')')

                             {

                                     int k=0;

                                     while(t[k]!='(')

                                     {

                                            a=a*10+(t[k]-'0');

                                            k++;

                                     }

                                      k++;

                                      while(t[k]!=')')

                                      {

                                             b=b*10+(t[k]-'0');

                                             k++;

                                      }

                                      e[i].sum+=a;

                                      e[i].ac+=b; 

                             }

                             else

                             e[i].sum+=atoi(t);   

                        }

                }

                e[i].sum+=e[i].ac*m; i++; 

        }   

        qsort(e,i,sizeof(e[0]),cmp);

        for(int  j=0;j<i;++j)

        printf("%-10s %2d %4d\n",e[j].s,e[j].flag,e[j].sum);

       // system("pause");

        return 0;

    }

  • 相关阅读:
    加载时间分析与优化
    t
    linux 3389
    切片声明 切片在内存中的组织方式 reslice
    从模版生成 uri Golang 的 html/template 包不太适合于这种情况
    负载均衡实现,一个域名对应多个IP地址
    京东首页 淘宝首页 图片加载 单域名 多域名 图片服务
    Reduce DNS Lookups 减少DNS查找
    Make Fewer HTTP Requests 减少HTTP请求
    What the 80/20 Rule Tells Us about Reducing HTTP Requests
  • 原文地址:https://www.cnblogs.com/yuelingzhi/p/2130729.html
Copyright © 2011-2022 走看看