#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
****************************************************************/
九度题目1061:成绩排序 2000年清华大学计算机研究生机试真题
最新推荐文章于 2018-02-28 20:28:14 发布