From f5dd47b6ca3704adebf6325ada17873733cfe6f0 Mon Sep 17 00:00:00 2001 From: p8sljnpht <3178612685@qq.com> Date: Sat, 16 Nov 2024 10:18:45 +0800 Subject: [PATCH] ADD file via upload --- 7.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 7.c diff --git a/7.c b/7.c new file mode 100644 index 0000000..48efc5a --- /dev/null +++ b/7.c @@ -0,0 +1,132 @@ +#include +#include + +struct Data +{ + int ID; + int Class; + float score1; + float score2; + float score3; + char name[101]; +} stu[1001]; +int stl = 0; +struct Data* stuflag = 0; + +float total(struct Data* a) { + return a->score1 + a->score2 + a->score3; +} + +void swap(struct Data* a, struct Data* b) { + struct Data t = *a; + *a = *b; + *b = t; + + if (a == stuflag) stuflag = b; +else + if (b == stuflag) stuflag = a; +} + +void Sort() { + int i, j; + for(i = 0; i < stl-1; i++) { + for (j = 0; j < stl-i-1; j++) { + if (stu[j].Class < stu[j+1].Class) continue; + if (stu[j].Class > stu[j+1].Class || + total(&stu[j]) < total(&stu[j+1])) swap(&stu[j], &stu[j+1]); + } + } +} + +void input1() { + scanf("%d", &stu[stl].ID); + scanf("%f", &stu[stl].score1); + scanf("%f", &stu[stl].score2); + scanf("%f", &stu[stl].score3); + stl++; +} + + +void Input() { + printf("Please input info of three students:\n"); + input1();input1();input1(); + if (total(&stu[stl-3]) < total(&stu[stl-2])) swap(&stu[stl-3], &stu[stl-2]); + if (total(&stu[stl-2]) < total(&stu[stl-1])) swap(&stu[stl-2], &stu[stl-1]); + if (total(&stu[stl-3]) < total(&stu[stl-2])) swap(&stu[stl-3], &stu[stl-2]); + printf("%d,%.1f,%.1f\n", stu[stl-3].ID, total(&stu[stl-3]), total(&stu[stl-3])/3.0f); + printf("%d,%.1f,%.1f\n", stu[stl-2].ID, total(&stu[stl-2]), total(&stu[stl-2])/3.0f); + printf("%d,%.1f,%.1f\n", stu[stl-1].ID, total(&stu[stl-1]), total(&stu[stl-1])/3.0f); +} + +void Print1(int i) +{ + printf("%d %d %s %.1f %.1f %.1f\n", stu[i].ID, stu[i].Class, stu[i].name, + stu[i].score1, stu[i].score2, stu[i].score3); +} + +void Search() { + int t; char com[101]; + int i; + scanf("%d %s", &t, com); + switch(t) { + case 1: { + int from, to; + sscanf(com, "%d-%d", &from, &to); + for (i=0; i= from && stu[i].Class <= to) + Print1(i); + } + }break; + case 2: { + int from, to; + sscanf(com, "%d-%d", &from, &to); + for (i=0; i= from && stu[i].ID <= to) + Print1(i); + } + }break; + case 3: { + for (i=0; i= gate - 0.01f) + Print1(i); + } + }break; + case 5: { + int Class, from, to; + sscanf(com, "%d.%d-%d", &Class, &from, &to); + for (i=0; i= from && stu[i].ID <= to) + if (stu[i].Class == Class) + Print1(i); + } + } + } +} + + +int main() { + stu[0] = (struct Data){10001, 11, 99.5, 88.5, 89.5, "Zhang"}; + stu[1] = (struct Data){10002, 12, 77.9, 56.5, 87.5, "Yang"}; + stu[2] = (struct Data){10003, 11, 92.5, 89.0, 60.5, "Liang"}; + stu[3] = (struct Data){10004, 11, 89.6, 56.9, 90.5, "Cai"}; + stu[4] = (struct Data){10005, 14, 55.6, 67.9, 98.9, "Fu"}; + stu[5] = (struct Data){10006, 12, 22.1, 45.9, 99.2, "Mao"}; + stu[6] = (struct Data){10007, 13, 35.6, 67.9, 88.0, "Zhan"}; + stl = 7; + Sort(); + Search(); +} \ No newline at end of file