HDU 2093 考试排名

 HDU 2093 考试排名 

/* HDU 2093 考试排名 */
#include <cstdio>
#include <string>
#include <queue>
#include <iostream>
using namespace std;

struct Node{
    string name;
    int n;
    int useTime;
    bool operator<(const Node& rhs) const {
        //先按从n的值从大到小排序
        //我是用rhs在前的方式记忆的,用rhs的项和当前项比较,大就放前面
        if (rhs.n > n){
            return 1;
        }
        else if (rhs.n == n){
            //n相等是useTime从小到大排序
            if (rhs.useTime < useTime)
                return 1;
            else if (rhs.useTime == useTime){
                //都相等时按名字从小到大排序
                if (rhs.name <= name)
                    return 1;
                else
                    return 0;
            }
            else
                return 0;
        }
        else
            return 0;
    }
};

priority_queue<Node> q;

int main()
{
    int n, m;
    int t, ch;
    scanf("%d%d", &n, &m);
    Node tmp;
    while (cin >> tmp.name){
        tmp.useTime = 0;
        tmp.n = 0;
        //输入n道题的成绩
        for (int i = 0; i < n; ++i){
            scanf("%d", &t);
            if (t > 0){
                ++tmp.n;
                tmp.useTime += t;
                if ((ch = getchar()) == '('){
                    scanf("%d", &t);
                    tmp.useTime += t*m;
                    getchar(); //吃掉 ')'
                }
            }
        }//for(i)
        q.push(tmp);
    }
    while (!q.empty()){
        tmp = q.top(); q.pop();
        printf("%-10s %2d %4d\n", tmp.name.c_str(), tmp.n, tmp.useTime);
    }

    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/tommychok/p/5074420.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值