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.
56 lines
1.1 KiB
56 lines
1.1 KiB
1 year ago
|
#include<stdio.h>
|
||
|
struct stu
|
||
|
{
|
||
|
int num,c,x;
|
||
|
float m,p,e,s;
|
||
|
};
|
||
|
|
||
|
struct stu stu[4]={{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 min(struct stu *stu,int n)
|
||
|
{
|
||
|
int i,j;
|
||
|
struct stu t;
|
||
|
for(i=0;i<n;i++)
|
||
|
{
|
||
|
for(j=0;j<n-i-1;j++)
|
||
|
{
|
||
|
if(((stu+j)->c>(stu+j+1)->c)||((stu+j)->c==(stu+j+1)->c)&&((stu+j)->s<(stu+j+1)->s))
|
||
|
{
|
||
|
t = *(stu+j);
|
||
|
*(stu+j) = *(stu+j+1);
|
||
|
*(stu+j+1) = t;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
scanf("%d",&stu[3].num);
|
||
|
scanf("%d",&stu[3].c);
|
||
|
scanf("%f",&stu[3].m);
|
||
|
scanf("%f",&stu[3].p);
|
||
|
scanf("%f",&stu[3].e);
|
||
|
stu[3].x=1;
|
||
|
stu[3].s=stu[3].m+stu[3].p+stu[3].e;
|
||
|
int z=1,i,n=4;
|
||
|
for(i=0;i<3;i++) if(stu[i].num==stu[3].num) z=0;
|
||
|
if(z==0) n=3;
|
||
|
for(i=0;i<3;i++){
|
||
|
if(stu[3].num==stu[i].num){
|
||
|
printf("%d existed\n",stu[i].num);
|
||
|
return 0;}}
|
||
|
min(stu,n);
|
||
|
for(i=0;i<n;i++)
|
||
|
{
|
||
|
printf("%d %d %.1f %.1f %.1f",stu[i].num,stu[i].c,stu[i].m,stu[i].p,stu[i].e);
|
||
|
if(stu[i].x) printf(" inserted");
|
||
|
printf("\n");
|
||
|
}
|
||
|
return 0;
|
||
|
}
|