文章

13

粉丝

64

获赞

0

访问

2.0k

头像
简洁
P1338 浙江大学机试题
发布于2024年3月22日 16:20
阅读数 201

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
struct Student
{
    string id;
    string name;
    int score;
};
bool cmp1(Student a, Student b)
{
    return a.id < b.id;
}
bool cmp2(Student a, Student b)
{
    if (a.name == b.name)
        return a.id < b.id;
    return a.name < b.name;
}
bool cmp3(Student a, Student b)
{
    if (a.score == b.score)
        return a.id < b.id;
    return a.score < b.score;
}
int main()
{
    int n, m;
    cin >> n >> m;
    vector<Student> stu(n);
    for (int i = 0; i < n; i++)
        cin >> stu[i].id >> stu[i].name >> stu[i].score;
    if (m == 1)
        sort(stu.begin(), stu.end(), cmp1);
    else if (m == 2)
        sort(stu.begin(), stu.end(), cmp2);
    else if (m == 3)
        sort(stu.begin(), stu.end(), cmp3);
    cout << "Case:" << endl;
    for (int i = ...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发