九度OJ 题目1187:最小年龄的3个职工
来源:互联网 发布:品源照明淘宝旗舰店 编辑:程序博客网 时间:2024/05/19 16:21
/********************************** 日期: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\n",wooker[i].ID,wooker[i].name,wooker[i].age);} } return 0;}