You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
121 lines
2.7 KiB
121 lines
2.7 KiB
#include <stdio.h>
|
|
//定义结构体
|
|
struct Student
|
|
{
|
|
int ID;//学号
|
|
int classes;
|
|
float math_grade;
|
|
float physics_grade;
|
|
float English_grade;
|
|
float sum;
|
|
};
|
|
|
|
int main()
|
|
{
|
|
struct Student information[4];
|
|
//已有三个同学的信息
|
|
information[0].ID=10001;information[0].classes=11;
|
|
information[0].math_grade=99.5;
|
|
information[0].physics_grade=88.5;
|
|
information[0].English_grade=89.5;
|
|
|
|
information[1].ID=10002;information[1].classes=12;
|
|
information[1].math_grade=77.9;
|
|
information[1].physics_grade=56.5;
|
|
information[1].English_grade=87.5;
|
|
|
|
information[2].ID=10003;information[2].classes=11;
|
|
information[2].math_grade=92.5;
|
|
information[2].physics_grade=99.0;
|
|
information[2].English_grade=60.5;
|
|
|
|
//输入新同学
|
|
scanf("%d%d%f%f%f",&information[3].ID,\
|
|
&information[3].classes,&information[3].math_grade,\
|
|
&information[3].physics_grade,&information[3].English_grade);
|
|
struct Student newstudent=information[3];
|
|
//判断是否已在系统里
|
|
if(newstudent.ID==information[0].ID||\
|
|
newstudent.ID==information[1].ID||\
|
|
newstudent.ID==information[2].ID)//新同学已在系统里
|
|
{
|
|
for(int i=0;i<=2;i++)
|
|
{
|
|
if(newstudent.ID==information[i].ID)
|
|
{
|
|
printf("%d %d %.1f %.1f %.1f \n",\
|
|
information[i].ID,information[i].classes,\
|
|
information[i].math_grade,information[i].physics_grade,\
|
|
information[i].English_grade);
|
|
}
|
|
}
|
|
}
|
|
else//新同学不在系统里
|
|
{
|
|
//排序:班级从小到大【顺便把每个人的成绩记录】
|
|
for(int i=0;i<=3;i++)
|
|
{
|
|
for(int j=0;j<=2;j++)
|
|
{
|
|
if(information[j].classes>information[j+1].classes)
|
|
{
|
|
struct Student tmp=information[j];
|
|
information[j]=information[j+1];
|
|
information[j+1]=tmp;
|
|
}
|
|
}
|
|
information[i].sum=+information[i].math_grade+\
|
|
information[i].physics_grade+information[i].English_grade;
|
|
}
|
|
|
|
//排序 :对同一班级排序
|
|
for(int i=0;i<=3;i++)
|
|
{
|
|
int con=0;//记录连续了几人
|
|
for(int j=1;j<=3-i;j++)
|
|
{
|
|
if(information[i].classes==information[i+j].classes)
|
|
{con++;
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
if(con)//有人是同班同学,在此内排序
|
|
{
|
|
for(int m=i;m<i+con;m++)
|
|
{
|
|
for(int n=i;n<=i+con-1;n++)
|
|
{
|
|
if(information[n].sum<information[n+1].sum)
|
|
{
|
|
struct Student tmp=information[n];
|
|
information[n]=information[n+1];
|
|
information[n+1]=tmp;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
i=i+con;
|
|
}
|
|
|
|
for(int i=0;i<=3;i++)
|
|
{
|
|
printf("%d %d %.1f %.1f %.1f ",information[i].ID,\
|
|
information[i].classes,information[i].math_grade,\
|
|
information[i].physics_grade,information[i].English_grade);
|
|
if(newstudent.ID==information[i].ID)
|
|
{
|
|
printf("inserted");
|
|
}
|
|
printf("\n");
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|