From f8e67f8abbfeac3a9bd85381264c405a7944e50a Mon Sep 17 00:00:00 2001 From: pv3e4i5aj Date: Sun, 17 Nov 2024 14:59:30 +0800 Subject: [PATCH] Add task6.cpp --- task6.cpp | 171 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 task6.cpp diff --git a/task6.cpp b/task6.cpp new file mode 100644 index 0000000..26bff94 --- /dev/null +++ b/task6.cpp @@ -0,0 +1,171 @@ +#include +#include + +//定义结构体 +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