文章

13

粉丝

120

获赞

1

访问

6.4k

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

#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 = ...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发