parent
260b67b66b
commit
f130757b9c
@ -0,0 +1,55 @@
|
||||
#include<stdio.h>
|
||||
#include<string.h>
|
||||
#define N 3
|
||||
|
||||
struct stu_info
|
||||
{
|
||||
char num[10];
|
||||
int cls,flag;
|
||||
float maths,physics,english;
|
||||
};
|
||||
|
||||
struct stu_info stu[N+1]={{"10001",11,0,99.5,88.5,89.5},
|
||||
{"10002",12,0,77.9,56.5,87.5},
|
||||
{"10003",11,0,92.5,99.0,60.5}};
|
||||
|
||||
void sort(struct stu_info *stu,int n)
|
||||
{
|
||||
int i,j;
|
||||
struct stu_info 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)->num>(stu+j+1)->num))
|
||||
{
|
||||
tmp = *(stu+j);
|
||||
*(stu+j) = *(stu+j+1);
|
||||
*(stu+j+1) = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
scanf("%s",&stu[3].num);
|
||||
scanf("%d",&stu[3].cls);
|
||||
scanf("%f",&stu[3].maths);
|
||||
scanf("%f",&stu[3].physics);
|
||||
scanf("%f",&stu[3].english);
|
||||
stu[3].flag=1;
|
||||
int i;
|
||||
sort(stu,N+1);
|
||||
for(i=0;i<N+1;i++)
|
||||
{
|
||||
printf("%s %.1f %.1f %.1f",stu[i].num,stu[i].maths,stu[i].physics,stu[i].english);
|
||||
if(stu[i].flag)
|
||||
{
|
||||
printf(" inserted");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in new issue