hdu 2093考试排名

#include<bits/stdc++.h>
using namespace std;
struct Stu{ char n[15]; int q, t;}s[10001];
int main(){
	int Q, T, cnt = 0, t, err;
    char tmp[100];
	scanf("%d %d", &Q, &T);
	while(scanf("%s", s[cnt+1].n) == 1){//输入结束的标志 
        cnt++;
		for(int i = 1; i <= Q; i++){
            scanf("%s", tmp);
            if(tmp[0] != '-' && tmp[0] != '0'){
                s[cnt].q++;
                if(sscanf(tmp, "%d(%d)", &t, &err) == 2){ // 格式化输入 
                    s[cnt].t += T*err;
                }
                s[cnt].t += t;
            }
        }
	}
    sort(s+1, s+cnt+1, [](Stu x, Stu y){
        if(x.q == y.q){
            if(x.t == y.t) return strcmp(x.n, y.n) < 0;
            return x.t < y.t;
        }
        return x.q > y.q;
    });
    for(int i = 1; i <= cnt; i++){
        printf("%-10s %2d %4d\n",s[i].n, s[i].q, s[i].t);//%-10s 表示左对齐10个字符宽 
    }
	return 0;
}
//sscanf sscanf的作用:从一个字符串中读进于指定格式相符的数据。
//利用它可以从字符串中取出整数、浮点数和字符串。 

添加链接描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值