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.

54 lines
1.1 KiB

#include<stdio.h>
#define N 3
struct student
{
int num,cls,flag;
float math,physics,english,total;
};
struct student stu[N+1]={{10001,11,0,99.5,88.5,89.5,277.5},
{10002,12,0,77.9,56.5,87.5,221.9},
{10003,11,0,92.5,99.0,60.5,252},{}};
void sort(struct student *stu,int n)
{
int i,j;
struct student tmp;
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(((stu+j)->cls>(stu+j+1)->cls)||((stu+j)->cls==(stu+j+1)->cls)&&((stu+j)->total<(stu+j+1)->total))
{
tmp = *(stu+j);
*(stu+j) = *(stu+j+1);
*(stu+j+1) = tmp;
}
}
}
return;
}
int main()
{
scanf("%d",&stu[N].num);
scanf("%d",&stu[N].cls);
scanf("%f",&stu[N].math);
scanf("%f",&stu[N].physics);
scanf("%f",&stu[N].english);
stu[N].flag=1;
stu[N].total=stu[N].math+stu[N].physics+stu[N].english;
int check=1,i,n=N+1;
for(i=0;i<N;i++) if(stu[i].num==stu[N].num) check=0;
if(!check) n--;
sort(stu,n);
for(i=0;i<n;i++)
{
printf("%d %d %.1f %.1f %.1f",stu[i].num,stu[i].cls,stu[i].math,stu[i].physics,stu[i].english);
if(stu[i].flag) printf(" inserted");
printf("\n");
}
return 0;
}