九度题目1061:成绩排序 2000年清华大学计算机研究生机试真题


 
#include <iostream>
#include<cstring>
using namespace std;
#include<stdio.h>
 
typedef struct special
{
    char name[101];
    int age;
    int score;
}Spe;
 
Spe S[1001];
bool operator <= (const Spe& A, const Spe& B)
{
    if (0 == strcmp(A.name, B.name) && A.age == B.age&&A.score == B.score)
    {
        return true;
    }
    if (A.score != B.score) return A.score < B.score;
    int temp = strcmp(A.name, B.name); //s1 < s2  == - 1
    if (temp != 0) return temp < 0;
    if (A.age != B.age) return A.age < B.age;
}
bool operator >= (const Spe& A, const Spe& B)
{
    if (0 == strcmp(A.name, B.name) && A.age == B.age&&A.score == B.score)
    {
        return true;
    }
    if (A.score != B.score) return A.score > B.score;
    int temp = strcmp(A.name, B.name); //s1 < s2  == - 1
    if (temp != 0) return temp > 0;
    if (A.age != B.age) return A.age > B.age;
}
void Qsort(Spe *input, int start, int end)
{
    if (NULL == input || start >= end) return;
    int L = start, R = end;
    Spe Index = input[start];
    while (L < R)
    {
        while (input[R] >= Index && L < R)
        {
            R--;
        }
        input[L] = input[R];
        while (input[L] <= Index && L < R)
        {
            L++;
        }
        input[R] = input[L];
    }
    input[L] = Index;
    Qsort(input, start, L - 1);
    Qsort(input, L + 1, end);
}
int main()
{
    int n = 0;
    int i = 0;
    int N = 0;
    while (cin >> n)
    {
        N = n - 1;
        for (i = 0; i < n; i++)
        {
            cin >> S[i].name >> S[i].age >> S[i].score;
        }
        Qsort(S, 0, N);//需重定义快排中的大小因子函数,改变默认的》,《;
        for (i = 0; i < n; i++)
        {
            printf("%s %d %d\n", S[i].name, S[i].age, S[i].score);
        }
    }
    return 0;
}
 
 
 
/**************************************************************
    Problem: 1061
    User: hrdjmax2
    Language: C++
    Result: Accepted
    Time:120 ms
    Memory:1628 kb
****************************************************************/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值