From 2fd98d5bbe72425e3ee5857ef3129c30592625c7 Mon Sep 17 00:00:00 2001 From: pv3e4i5aj Date: Sun, 17 Nov 2024 14:58:50 +0800 Subject: [PATCH] Add task5.cpp --- task5.cpp | 189 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 task5.cpp diff --git a/task5.cpp b/task5.cpp new file mode 100644 index 0000000..ab43612 --- /dev/null +++ b/task5.cpp @@ -0,0 +1,189 @@ +#include +#include + +#define MARK 10 + +//定义结构体 +struct Student +{ + int ID;//学号 + int classes; + char name[8]; + float math_grade; + float physics_grade; + float English_grade; + float sum; +}; + +//对结构体中的从start同学到end同学排序 +void Sort(struct Student information[4],int start,int end) +{ + //先班级 + for(int i=start;i<=end;i++) + { + for(int j=start;j<=end-1;j++) + { + if(information[j].classes>information[j+1].classes) + { + struct Student tmp=information[j]; + information[j]=information[j+1]; + information[j+1]=tmp; + } + } + } + //同班同学再成绩 + for(int i=start;i<=end;i++) + { + int con=0;//记录连续了几人 + for(int j=1;j<=end-i;j++) + { + if(information[i].classes==information[i+j].classes) + {con++; + } + else + { + break; + } + } + + if(con)//有人是同班同学,在此内排序 + { + for(int m=i;m='0') + { + int num=0; + for(int i=0;i