From e750246422184cc6cd7a70fc0156026bac898278 Mon Sep 17 00:00:00 2001 From: plwhm8ti7 <1736991355@qq.com> Date: Sun, 12 Nov 2023 09:40:47 +0800 Subject: [PATCH] ADD file via upload --- 4,5.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 4,5.cpp 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;}