码迷,mamicode.com
首页 > 编程语言 > 详细

1752: 学生数据排序

时间:2020-02-06 20:21:54      阅读:69      评论:0      收藏:0      [点我收藏+]

标签:std   include   oid   输出   个学生   i++   core   i+1   print   

#include<stdio.h>
struct student
{
char name[9];
long no;
int score[4];
};
void input(struct student stu[100],int n)
{
int i;
for(i=1;i<=n;i++)
{
scanf("%ld %s %d %d %d",&stu[i].no,&stu[i].name,&stu[i].score[1],&stu[i].score[2],&stu[i].score[3]);
stu[i].score[0]=stu[i].score[1]+stu[i].score[2]+stu[i].score[3];
}
return;
}
void sort(struct student stu[100],int n)
{
struct student t;
int i,j;
for(i=1;i<=n;i++)
for(j=i+1;j<=n;j++)
{
if(stu[i].score[0]<stu[j].score[0] || stu[i].score[0]==stu[j].score[0] && stu[i].no>stu[j].no)
{
t=stu[i];
stu[i]=stu[j];
stu[j]=t;
}
}
return;
}
void print(struct student stu[100],int n)
{
int i;
for(i=1;i<=n;i++)
{
printf("%d ",i);
printf("%ld %s %d %d %d %d\n",stu[i].no,stu[i].name,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3]);
}
return;
}
int main()
{
int n;
struct student stu[100];
while(scanf("%d",&n)!=EOF)
{
input(stu,n); //读入n个学生的数据
sort(stu,n); //按照总分降序排序,如果总分相同的学号小的在前面
print(stu,n); //输出n个学生的信息
}
return 0;
}

1752: 学生数据排序

标签:std   include   oid   输出   个学生   i++   core   i+1   print   

原文地址:https://www.cnblogs.com/cy846586184/p/12269773.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!