【hdu 2093】 考试排名

思路

读入比较麻烦,用类似读入优化的办法,读进数来以后,用结构体排序。

代码

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
struct node{
    char name[101];
    int ac, time;
    node(){ac = 0, time = 0;}
    bool operator < (const node &a)const{
        return ac == a.ac ? time < a.time : ac > a.ac;
    }
};
node tt[10010];
int n, p, cnt, ct, let;
char ch[1010];
inline int getint(){
    char c;
    int ok = 0, num = 0, op = 1;
    if(ct >= let) return 0;
    while((c = ch[++ct]) || 1){
        if(c == '-') op = -1;
        else if(c <= '9' && c >= '0') ok = 1, num = num*10 + c - '0';
        else if(ok || c == '\0') return op*num;
    }
}
int main(){
    scanf("%d%d", &n, &p);
    while(1){
        if(scanf("%s", tt[++cnt].name+1) == EOF){
            cnt --;
            break;
        }
        int ac = 0, time1 = 0;
        for(int i = 1; i <= n; i ++){
            scanf("%s", ch+1), ct = 0;
            let = strlen(ch+1);
            int t = getint(), ttt;
            if(t <= 0) continue;
            if(t > 0){
                ac ++;
                ttt = getint();
                time1 += (ttt*p+t);
            } 
        //  else time1 += (-1*t*p);
        }
        tt[cnt].ac = ac;
        tt[cnt].time = time1;
    }
    sort(tt+1, tt+1+cnt);
    for(int i = 1; i <= cnt; i ++){
        printf("%-10s %2d %4d\n", tt[i].name+1, tt[i].ac, tt[i].time);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值