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.
74 lines
1.3 KiB
74 lines
1.3 KiB
1 year ago
|
#include<stdio.h>
|
||
|
#include<string.h>
|
||
|
#define N 3
|
||
|
|
||
|
struct stu_info
|
||
|
{
|
||
|
char num[10];
|
||
|
int cls,flag;
|
||
|
char name[10];
|
||
|
float maths,physics,english;
|
||
|
};
|
||
|
|
||
|
struct stu_info stu[N]={{"10001",11,0,"Zhang",99.5,88.5,89.5},
|
||
|
{"10002",12,0,"Yang",77.9,56.5,87.5},
|
||
|
{"10003",11,0,"Liang",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()
|
||
|
{
|
||
|
struct stu_info q;
|
||
|
scanf("%s",&q.num);
|
||
|
scanf("%d",&q.cls);
|
||
|
scanf("%s",&q.name);
|
||
|
scanf("%f",&q.maths);
|
||
|
scanf("%f",&q.physics);
|
||
|
scanf("%f",&q.english);
|
||
|
int i;
|
||
|
for(i=0;i<N;i++)
|
||
|
{
|
||
|
if(strcmp(stu[i].num,q.num)==0)
|
||
|
{
|
||
|
*(stu+i)=q;
|
||
|
stu[i].flag=1;
|
||
|
}
|
||
|
}
|
||
|
sort(stu,N);
|
||
|
for(i=0;i<N;i++)
|
||
|
{
|
||
|
if(i==0||stu[i].cls!=stu[i-1].cls)
|
||
|
{
|
||
|
printf("%2d ",stu[i].cls);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printf(" ");
|
||
|
}
|
||
|
printf("%s %s %.1f %.1f %.1f",stu[i].num,stu[i].name,stu[i].maths,stu[i].physics,stu[i].english);
|
||
|
if(stu[i].flag)
|
||
|
{
|
||
|
printf(" modified");
|
||
|
}
|
||
|
printf("\n");
|
||
|
}
|
||
|
return 0;
|
||
|
}
|