ADD file via upload

main
p7cx2jokr 10 hours ago
parent 467dc8ad70
commit b1fdc82907

48
4.c

@ -0,0 +1,48 @@
#include <stdio.h>
#include <string.h>
struct student{
int clas,inserted;
char id[20];
double score1,score2,score3,total;
}s[10];
void input(){
int i,j,cnt=0;
for(i=0;i<4;i++){
scanf("%s%d%lf%lf%lf",s[i].id,&s[i].clas,&s[i].score1,&s[i].score2,&s[i].score3);
cnt++;
if(i!=3) s[i].inserted=0;
else s[i].inserted=1;
for(j=0;j<i;j++){
if(strcmp(s[i].id,s[j].id)==0){
cnt--;
}
}
s[i].total=s[i].score1+s[i].score2+s[i].score3;
}
for(i=0;i<cnt-1;i++){
for(j=0;j<cnt-i-1;j++){
if(s[j].clas>s[j+1].clas||(s[j].clas==s[j+1].clas&&s[j].total<s[j+1].total)){
struct student t;
t=s[j];
s[j]=s[j+1];
s[j+1]=t;
}
}
}
for(i=0;i<cnt;i++){
printf("%s %d %.1f %.1f %.1f",s[i].id,s[i].clas,s[i].score1,s[i].score2,s[i].score3);
if(s[i].inserted==1) printf(" inserted");
printf("\n");
}
}
int main(){
input();
return 0;
}
//10001 11 99.5 88.5 89.5
//10002 12 77.9 56.5 87.5
//10003 11 92.5 99.0 60.5
//1004 11 23.4 45.6 99.0
Loading…
Cancel
Save