From 9d56705683dde0c359eff376fd49c34dd66b0ff8 Mon Sep 17 00:00:00 2001 From: pm6lnt93v <1289474397@qq.com> Date: Wed, 20 Nov 2024 16:58:11 +0800 Subject: [PATCH] ADD file via upload --- main.c | 325 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 325 insertions(+) create mode 100644 main.c diff --git a/main.c b/main.c new file mode 100644 index 0000000..d245c25 --- /dev/null +++ b/main.c @@ -0,0 +1,325 @@ +#include +#include +#pragma warning (disable:4996) + +typedef struct Student +{ + char id[20]; + char clas[20]; + char name[20]; + double score1; + double score2; + double score3; + double score; +}Student; + +Student stu[50]={{"10001","11","Zhang",99.5,88.5,89.5,277.5},{"10002","12","Yang",77.9,56.5,87.5,221.9},{"10003","11","Liang",92.5,99.0,60.5,252.0}}; + + +void start() +{ + printf("\n以下为主菜单:\n"); + printf(" 1.input\n"); + printf(" 2.delete\n"); + printf(" 3.select\n"); + printf(" 4.order\n"); + printf(" 5.output\n"); + printf(" 6.quit\n"); + printf("please input your option:\n"); +}//开始显示主菜单的函数 + +void input() +{ int i;int flag=1; + int len=lens(stu); + scanf("%s %s %s %lf %lf %lf", stu[len].id,stu[len].clas,&stu[len].name,&stu[len].score1, &stu[len].score2, &stu[len].score3); + char nul3=getchar(); + stu[len].score = stu[len].score1 + stu[len].score2 + stu[len].score3; + for(i=0;i stu[j + 1].score) + { + Student temp = stu[j]; + stu[j] = stu[j + 1]; + stu[j + 1] = temp; + } + } + } + for( i=0;i 0) + { + court++; + } + if(stu[i].score3 <= 0) + { + break; + } + } + return court; +} //测学生数量 + +void order() +{ + int i,j,k; + int a[100] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; + int c[100] = { 0 }; + int number = 0; + int len = lens(stu); + for (i = 0;i < len;i++) + { + stu[i].score = stu[i].score1 + stu[i].score2 + stu[i].score3; + } + stu[len + 1].score = 0; + for (i = 0;i < len;i++) + { + for (j = 0;j < len - i-1;j++) + { + if (strcmp(stu[j].clas, stu[j + 1].clas) > 0) + { + stu[len + 1] = stu[j]; + stu[j] = stu[j + 1]; + stu[j + 1] =stu[len + 1]; + } + } + } + + stu[len].score = 6458; + for (i = 0;i < len;i++) + { + if (stu[i].score == stu[i + 1].score) + { + a[number]++; + } + if (stu[i].score != stu[i + 1].score) + { + a[number]++; + c[number + 1] = i + 1; + number++; + } + } + for (k = 0;k < number;k++) + { + + for (i = 0;i < a[k];i++) + { + for (j = c[k];j < a[k] - i;j++) + { + if (stu[j].score < stu[j + 1].score) + { + stu[len + 1] = stu[j]; + stu[j] = stu[j + 1]; + stu[j + 1] = stu[len + 1]; + } + } + } + } + for (i = 0;i < len;i++) + { + printf("%s %s %.2f %.2f %.2f %.2f\n", stu[i].id, stu[i].clas, stu[i].score1, stu[i].score2, stu[i].score3, stu[i].score); + } +} //先按班级再按成绩排序 + +void delete() +{ + int len = lens(stu);int flag = 0; + int i,j,k; + printf("请输入要删除学生的学号或者姓名:\n"); + char a[10];//用来储存学号或者名字 + scanf("%s", a); + char nul2=getchar(); + for (i = 0;i < len;i++) + { + if (strcmp(a, stu[i].id) == 0 || strcmp(a, stu[i].name) == 0) + { + flag = 1;//有的话删除并输出 + for (k = i + 1;k < len;k++) + { + stu[k - 1] = stu[k];//相当于删除 + } + + + } + } + if (flag == 0)//没有的话输出原来的数据 + { + for (j = 0;j < len;j++) + { + printf("%s %s %s %.2f %.2f %.2f %.2f\n", stu[j].id,stu[j].clas, stu[j].name, stu[j].score1, stu[j].score2, stu[j].score3, stu[j].score); + } + + } + if (flag == 1)//有的话输出这个之外的(已删除这个学生) + { + len = lens(stu) - 1; + for (j = 0;j < len;j++) + { + printf("%s %s %s %.2f %.2f %.2f %.2f\n", stu[j].id,stu[j].clas, stu[j].name, stu[j].score1, stu[j].score2, stu[j].score3, stu[j].score); + } + } +} //删除 + +void select(char* a,char* b,int i,double k) +{ + int len = lens(stu),j; + if (i == 1) + { + for (j = 0;j < len;j++) + { + if (strcmp(stu[j].clas,a)>=0 && strcmp(stu[j].clas,b)<=0) + { + printf("%s %s %s %.2f %.2f %.2f %.2f\n", stu[j].id, stu[j].clas, stu[j].name, stu[j].score1, stu[j].score2, stu[j].score3, stu[j].score); + } + } + } + else if (i == 2) + { + for (j = 0;j < len;j++) + { + if (strcmp(stu[j].id,a)>=0 && strcmp(stu[j].id,b)<=0) + { + printf("%s %s %s %.2f %.2f %.2f %.2f\n", stu[j].id, stu[j].clas, stu[j].name, stu[j].score1, stu[j].score2, stu[j].score3, stu[j].score); + } + } + } + else if (i == 3) + { + for (j = 0;j < len;j++) + { + if(strcmp(stu[j].name,a)>=0 && strcmp(stu[j].name,b)<=0) + { + printf("%s %s %s %.2f %.2f %.2f %.2f\n", stu[j].id, stu[j].clas, stu[j].name, stu[j].score1, stu[j].score2, stu[j].score3, stu[j].score); + } + } + } + else if (i == 4) + { + for (j = 0;j < len;j++) + { + if (stu[j].score>=k) + { + printf("%s %s %s %.2f %.2f %.2f %.2f\n", stu[j].id, stu[j].clas, stu[j].name, stu[j].score1, stu[j].score2, stu[j].score3, stu[j].score); + } + } + } +} //a表示初始,b表示末尾 + + +int main() +{ + while(1) + { + start(); + char g = getchar(); + char nul=getchar(); + if (g == '1') + { + printf("Please input info of a student(格式为id clas name score1 score2 score3):\n"); + input(); + } + else if(g=='4') + { + order(); + } + else if(g=='5') + { + output(); + } + else if(g=='2') + { + delete(); + } + else if(g=='3') + { + char a[20],b[20]; + int t; + double k; + printf("选择筛选的方式\n1.按班级\n2.按学号\n3.按姓名\n4.按总分\n"); + scanf("%d",&t); + nul=getchar(); + if(t>=1&&t<=3) + { + printf("请输入要求的范围:\nbegin:"); + scanf("%s",a); + printf("end:"); + scanf("%s",b); + nul=getchar(); + select(a,b,t,0); + } + else if(t==4) + { + printf("请输入要大于等于的总分\n"); + scanf("%lf\n",k); + nul=getchar(); + select(a,b,t,k); + } + } + else if(g=='6') + { + break; + } + else printf("输入错误"); + printf("continue?\n"); + char s[100]; + scanf("%s",s); + nul=getchar(); + char* yes="yes"; + if(strcmp(s,yes)==0){} + else break; + } + return 0; +} + +