2 solutions

  • 0
    @ 2023-10-18 12:49:24
    #include <stdio.h>
    int main()
    {
        struct student
        {
            int num;
            float a;
            float b;
        };
        int n;
        scanf("%d", &n);
        struct student stu[10000];
        struct student* p;
        p = &stu;
        struct student k;
        int i, j;
        for (i = 0; i < n; i++)
        {
            stu[i].num = i + 1;
        }
        for (i = 0; i < n; i++)
        {
            scanf("%f%f", &(*p).a, &(*p).b);
            p++;
        }
        for (i = 0; i < n - 1; i++)
        {
            for (j = i + 1; j < n; j++)
            {
                if (stu[i].a > stu[j].a)
                {
                    k = stu[i];
                    stu[i] = stu[j];
                    stu[j] = k;
                }
                if (stu[i].a == stu[j].a)
                {
                    if (stu[i].b > stu[j].b)
                    {
                        k = stu[i];
                        stu[i] = stu[j];
                        stu[j] = k;
                    }
                    else if (stu[i].b == stu[j].b)
                    {
                        if (stu[i].num > stu[j].num)
                        {
                            k = stu[i];
                            stu[i] = stu[j];
                            stu[j] = k;
                        }
                    }
                }
            }
        }
        for (i = 0; i < n; i++)
            printf("%d ", stu[i].num);
        return 0;
    }
    

    Information

    ID
    6828
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    7
    Tags
    # Submissions
    98
    Accepted
    20
    Uploaded By