1028 List Sorting (25)(25 分)

#include
#include
#include
using namespace std;
int n, c;
const int maxn = 1e5 + 10;
struct node {
    char id[100], name[100];
    int score;
    
}a[maxn];
bool comp1(node&x, node&y)
{
    return strcmp(x.id, y.id) < 0;
}
bool comp2(node&x, node&y)
{
    return strcmp(x.name, y.name) == 0 ? strcmp(x.id, y.id) < 0 : strcmp(x.name, y.name) < 0;
}
bool comp3(node&x, node&y)
{
    return x.score == y.score ? strcmp(x.id, y.id) < 0 : x.score < y.score;
}
int main()
{
    scanf("%d%d", &n, &c);
    for (int i = 0; i < n; i++)
    {
        scanf("%s%s%d", a[i].id, a[i].name, &a[i].score);
    }
    if (c == 1)sort(a, a + n, comp1);
    else if (c == 2)sort(a, a + n, comp2);
    else sort(a, a + n, comp3);
    for (int i = 0; i < n; i++)
        printf("%s %s %d\n", a[i].id, a[i].name, a[i].score);
    return 0;
}

你可能感兴趣的:(1028 List Sorting (25)(25 分))