hdu 2093 考试排名

来源:互联网 发布:p站软件 编辑:程序博客网 时间:2024/05/17 00:47
#include <stdio.h>#include <algorithm>#include <string.h>using namespace std;struct STU{    char name[20];    int sum;    int cnt;} s[1000];int cmp(STU x,STU y)//先按题数排,再按总时间小的在头排序{    if(x.cnt!=y.cnt)        return x.cnt>y.cnt;    return x.sum<y.sum;}int main(){    int n,t;    while(~scanf("%d%d",&n,&t))    {        int i,j,k = 0;        char sc[100];        while(~scanf("%s",s[k].name))        {            s[k].sum = s[k].cnt = 0;            for(i = 0; i<n; i++)            {                scanf("%s",sc);                if(!strcmp(sc,"0"))//没提交,自然不算                    continue;                if(sc[0] == '-')//提交的都是错的,而且没A,也不算                    continue;                s[k].cnt++;                int len = strlen(sc),f = 0,l = 0;                if(!strstr(sc,"("))//没有括号代表1A,,直接算                {                    while(sc[l])                    {                        f = f*10+sc[l]-'0';                        l++;                    }                    s[k].sum+=f;                    continue;                }                while(sc[l]!='(')//有括号就要算出提交的时间                {                    f = f*10+sc[l]-'0';                    l++;                }                s[k].sum+=f;                f = 0;                l++;                while(sc[l]!=')')//罚时                {                    f = f*10+sc[l]-'0';                    l++;                }                f = f*t;                s[k].sum+=f;            }            k++;        }        sort(s,s+k,cmp);        for(i = 0; i<k; i++)        {            printf("%-10s%3d%5d\n",s[i].name,s[i].cnt,s[i].sum);        }    }    return 0;}

0 0
原创粉丝点击