hdu2093 考试排名

#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;

}

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值