PAT A1025 PAT Ranking (25 分) 排序

博客详细解析了PAT A1025题目的内容,主要涉及排序算法的应用。通过输入考场及考生信息,计算并输出每个考生的总排名、考场排名和所在考场。博主提供了AC代码实现这一功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    题目大意:给出N个考场的所有考生的信息,要求按照成绩排名,输出每个考生的 总排名、考场排名、和所在考场。

    排序题,输入完每个考场的考生信息时,可以一次排序得到该考生的考场排名,输入完全部考场信息后再来一次排序,可以得到所有考生的总排名。

AC代码:

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>

using namespace std;

struct student
{
    string id;
    int score;
    int finalRank;
    int localRank;
    int location;
    student(string id, int score, int location):id(id), score(score), location(location){};
    bool operator< (const student &other)
    {
        if(this->score != other.score) return this->score > other.score;
        return this->id < other.id;
    }
};

int main()
{
    int N;
    cin >> N;
    vector<student> totalStu;
    for (int i = 1; i <= N; ++i)
    {
        int K;
        cin >> K;
        vector<student> v;
        for (int j &#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值