解题思路:
注意事项:
参考代码:
#include<stdio.h>
#include<string.h>
struct student{
char name[101];
int x;
int y;
};
int main()
{
int n;
struct student t;
struct student stu[1010];
while(scanf("%d",&n)!=EOF){
for(int i=0;i<n;i++){
scanf("%s %d %d",&stu[i].name,&stu[i].x,&stu[i].y);
getchar();
}
for(int i=0;i<n-1;i++){
for(int j=0;j<n-1-i;j++){
if(stu[j].y>stu[j+1].y){
t=stu[j];
stu[j]=stu[j+1];
stu[j+1]=t;
}
if(stu[j].y==stu[j+1].y){
if(strcmp(stu[j].name,stu[j+1].name)>0){
t=stu[j];
stu[j]=stu[j+1];
stu[j+1]=t;
}
else if(strcmp(stu[j].name,stu[j+1].name)==0){
if(stu[j].x>stu[j+1].x){
t=stu[j];
stu[j]=stu[j+1];
stu[j+1]=t;
}
}
}
}
}
for(int i=0;i<n;i++){
printf("%s %d %d\n",stu[i].name,stu[i].x,stu[i].y);
}
}
return 0;
}
0.0分
0 人评分
C二级辅导-分段函数 (C语言代码)浏览:533 |
C二级辅导-计负均正 (C语言代码)浏览:507 |
字符串比较 (C语言代码)答案错误????浏览:597 |
WU-C语言程序设计教程(第三版)课后习题11.11 (C++代码)(想学链表的可以看看)浏览:1357 |
简单的a+b (C语言代码)浏览:817 |
DNA (C语言描述,蓝桥杯)浏览:1555 |
母牛的故事 (C语言代码)浏览:715 |
文科生的悲哀 (C语言代码)浏览:1401 |
A+B for Input-Output Practice (III) (C语言代码)浏览:569 |
Tom数 (C语言代码)浏览:495 |