1 #include "stdio.h" 2 #include "stdlib.h" 3 #include "string.h" 4 #include <iostream> 5 using namespace std; 6 typedef struct student 7 { 8 int age,grade; 9 char a[100]; 10 }student; 11 int main() 12 { 13 int n,i,visit[10000],min,record,j; 14 student *s=(student*)malloc(1000*sizeof(student));//只需第一次时分配,不然超出内存 15 while(scanf("%d",&n)!=EOF){//没看清条件是多组,只看了示例输入 16 i=0;//初始化都应放在循环里 17 min=101; 18 memset(visit,0,sizeof(visit)); 19 while(i<n) 20 { 21 scanf("%s %d %d",s[i].a,&s[i].age,&s[i].grade); 22 i++; 23 } 24 for(j=0;j<n;j++) 25 { 26 min=101; 27 for(i=0;i<n;i++) 28 { 29 if(visit[i]==0&&min>s[i].grade) 30 { 31 record=i; 32 min=s[i].grade;//这个不应该忘记 33 } 34 else if(visit[i]==0&&min==s[i].grade) 35 { 36 if(strcmp(s[record].a,s[i].a)>0) 37 { 38 record=i; 39 min=s[i].grade; 40 } 41 else if(strcmp(s[record].a,s[i].a)==0) 42 if(s[record].age>s[i].age) 43 { 44 record=i; 45 min=s[i].grade; 46 } 47 } 48 } 49 visit[record]=1; 50 printf("%s %d %d\n",s[record].a,s[record].age,s[record].grade); 51 } 52 } 53 return 0; 54 }