HDU2093-考试排名-模拟-水题

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2093

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
const int N=10005;
int n,m;
struct node
{
    char name[20];
    int cnt;
    int score;
}stu[N];
bool cmp(node x,node y)     //  结构体排序;
{
    if(x.cnt!=y.cnt) return x.cnt>y.cnt;
    else if(x.score!=y.score) return x.score<y.score;
    else return strcmp(x.name,y.name)<0;
}
int main()
{
    while(~scanf("%d%d",&n,&m)){
        int t=0;
        char ch[10];
        while(scanf("%s",stu[t].name)!=EOF){
            stu[t].cnt=0;stu[t].score=0;
            for(int i=0;i<n;i++){
                scanf("%s",ch);
                if(ch[0]=='-') continue;        //  等于负数,说明没有A;
                if(strcmp(ch,"0")==0) continue;     //  同样是没有AC;
                stu[t].cnt++;   //  AC了计数++;
                int j,tmp=0;
                for(j=0;j<strlen(ch);j++){
                    if(ch[j]=='(') break;
                    tmp=tmp*10+ch[j]-'0';
                }
                stu[t].score+=tmp;
                tmp=0;
                if(j<strlen(ch)){       //  说明并不是1A;计算罚时;
                    for(int k=j+1;k<strlen(ch)-1;k++){
                        tmp=tmp*10+ch[k]-'0';
                    }
                }
                stu[t].score+=tmp*m;
            }
            //cout<<t<<endl;
            //if(t==5) break;
            t++;
        }
        sort(stu,stu+t,cmp);                                                                                                             for(int i=0;i<t;i++){                                                                                                            printf("%-10s%3d%5d\n",stu[i].name,stu[i].cnt,stu[i].score);
        }
    }
    return 0;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值