点击打开链接
/*
时间:2014.2.1
目的:题目1187:最小年龄的3个职工http://ac.jobdu.com/problem.php?pid=1187
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct ZG{
int ID;
char name[11];
int age;
}ZG;
ZG zg[30];
int cmp(const void*a,const void*b)
{
struct ZG *m = (ZG*)a;
struct ZG *n = (ZG*)b;
if(m->age!=n->age)
return m->age-n->age;
else if(m->ID!=n->ID)
return m->ID - n->ID;
else
return strcmp(m->name,n->name);
}
int main()
{
int n, i;
while(~scanf("%d", &n))
{
for(i = 0;i < n;i ++)
scanf("%d %s %d",&zg[i].ID,zg[i].name,&zg[i].age);
qsort(zg,n,sizeof(ZG),cmp);
if(n <= 2)
{
for(i = 0;i < n;i++)
printf("%d %s %d\n",zg[i].ID,zg[i].name,zg[i].age);
continue;
}
for(i = 0;i < 3;i++)
printf("%d %s %d\n",zg[i].ID,zg[i].name,zg[i].age);
}
return 0;
}
/*
-------------------------
5 思路:1.qsort()
501 Jack 6
102 Nathon 100
599 Lily 79
923 Lucy 15
814 Mickle 65
501 Jack 6
923 Lucy 15
814 Mickle 65
-------------------------
*/