解题思路:
注意事项:
参考代码:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define maxsize 100000
typedef struct
{
char id[19];
char age[9];
}people;
int compare(const void* a, const void* b)
{
people* A = (people*)a;
people* B = (people*)b;
if (strcmp(A->age, B->age) != 0)
return strcmp(B->age, A->age);
else
return strcmp(B->id, A->id);
}
int main()
{
int i, n,j;
scanf("%d", &n);
people *x;
x = (people*)malloc(sizeof(people) * n);
if (x == NULL)
return 0;
for (i = 0; i < n; i++)
scanf("%s",x[i].id);
for (i = 0; i < n; i++)
{
for (j = 0; j <=7;j++)
{
x[i].age[j] = x[i].id[j + 6];
}
x[i].age[j] = '\0';
}
qsort(x, n, sizeof(people), compare);
for (i = 0; i < n; i++)
printf("%s\n", x[i].id);
return 0;
}
0.0分
1 人评分