diff --git a/4,5.cpp b/4,5.cpp new file mode 100644 index 0000000..7dfa658 --- /dev/null +++ b/4,5.cpp @@ -0,0 +1,60 @@ +#include +int main() +{ +struct data + { + long int num; + long int clas; + char name[20]; + float grade1; + float grade2; + float grade3; + }; + struct data stud[3]={10001,11,"zhang",99.5,88.5,89.5,10002,12,"yang",77.9,56.5,87.5,10003,11,"liang",92.5,99.0,60.5}; + struct data stu;//{10001,11,"zhang",99,88,89}; + printf("ÇëÊäÈë´ýÐ޸ĵÄѧÉúÐÅÏ¢\n"); + scanf("%ld %ld %s %f %f %f",&stu.num,&stu.clas,&stu.name,&stu.grade1,&stu.grade2,&stu.grade3); + for(int i=0;i<3;i++) + { + if(stu.num==stud[i].num) + { + stud[i].grade1=stu.grade1; + stud[i].grade2=stu.grade2; + stud[i].grade3=stu.grade3; + } + break; + } + struct data temp; + for(int i=0;i<3;i++) + { + for(int j=i+1;j<3;j++) + { + if(stud[i].clas>stud[j].clas) + { + temp=stud[i]; + stud[i]=stud[j]; + stud[j]=temp; + } + } + } + for(int i=0;i<3;i++) + { + for(int j=i+1;j<3;j++) + { + if(stud[i].num>stud[j].num&&stud[i].clas==stud[j].clas) + { + temp=stud[i]; + stud[i]=stud[j]; + stud[j]=temp; + } + } + } + for(int i=0;i<3;i++) + { + if(i>0&&stud[i].clas==stud[i-1].clas) + printf(" %ld %s %3.1f %3.1f %3.1f",stud[i].num,stud[i].name,stud[i].grade1,stud[i].grade2,stud[i].grade3); + else printf("%d %ld %s %3.1f %3.1f %3.1f",stud[i].clas,stud[i].num,stud[i].name,stud[i].grade1,stud[i].grade2,stud[i].grade3); + if(stud[i].num==stu.num) printf(" modified"); + printf("\n"); + } + return 0;}