九度OJテーマ1187:最小年齢の3人の従業員

1294 ワード

/*********************************
*     :2013-2-9
*     :SJF0115
*     :   OJ   1187:     3   
*     :http://ac.jobdu.com/problem.php?pid=1187
*     :AC
*     :2003-2005                 
*     :
**********************************/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct Wooker{
	int ID;
	int age;
	char name[10];
}Wooker;
//     :  >  >  ,    。
int cmp(const void *a,const void *b){
	struct Wooker* c = (Wooker*) a;
	struct Wooker* d = (Wooker*) b;
	if(c->age != d->age){
		return c->age - d->age;
	}
	else if(c->ID != d->ID){
		return c->ID - d->ID;
	}
	else{
		return strcmp(c->name,d->name);
	}
}
int main()
{
	int n,i;
	//freopen("C:\\Users\\SJF\\Desktop\\acm.txt","r",stdin);
	Wooker wooker[100];
    while(scanf("%d",&n) != EOF)
    {
		//   (  ),   (   ,     10),   (1<=age<=100)。
		for(i = 0;i < n;i++){
			scanf("%d %s %d",&wooker[i].ID,wooker[i].name,&wooker[i].age);
		}
		//  
		qsort(wooker,n,sizeof(wooker[0]),cmp);
		//       N 3    
		if(n > 3){
			n = 3;
		}
		//  
		for(i = 0;i < n;i++){
			printf("%d %s %d
",wooker[i].ID,wooker[i].name,wooker[i].age); } } return 0; }