From e26918080eefc28ff3bf03ff5c090c4da776dbdc Mon Sep 17 00:00:00 2001 From: pv7g39eqr <2500187549@qq.com> Date: Sun, 12 Nov 2023 19:13:39 +0800 Subject: [PATCH] ADD file via upload --- 7.cpp | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 7.cpp diff --git a/7.cpp b/7.cpp new file mode 100644 index 0000000..7a352ae --- /dev/null +++ b/7.cpp @@ -0,0 +1,140 @@ +#include +#include +struct Info +{ + char num[6], name[7]; + int cls; + float math, phy, eng, sum, ave; +}arr[7]={{10001,11,"Zhang",99.5,88.5,89.5,0,0}, + {10002,12,"Yang",77.9,56.5,87.5,0,0}, + {10003,11,"Ling",92.5,99.0,60.5,0,0}, + {10004,11,"Cai",89.6,56.9,90.5,0,0}, + {10005,14,"Fu",55.6,67.9,98.9,0,0}, + {10006,12,"Mao",22.1,45.9,99.2,0,0}, + {10007,13,"Zhan",35.6,67.9,88.0,0,0}}; +struct Info ins, mod; +void Input(int i) +{ + scanf("%s", arr[i].num); + scanf("%d", &arr[i].cls); + scanf("%s", arr[i].name); + scanf("%f%f%f", &arr[i].math, &arr[i].phy, &arr[i].eng); + arr[i].sum = arr[i].math + arr[i].phy + arr[i].eng; + arr[i].ave = arr[i].sum / 3.0; +} +void Output(int i) +{ + /*if (i == 0 || arr[i].cls != arr[i - 1].cls) + printf("%d ", arr[i].cls) + else + printf(" ");*/ + printf("%s ", arr[i].num); + printf("%d ", arr[i].cls); + printf("%s ", arr[i].name); + printf("%.1f %.1f %.1f", arr[i].math, arr[i].phy, arr[i].eng); + printf("\n"); +} +void Rank(struct Info arr[],int s) +{ + for (int i = 0; i < s; i++) + for (int j = s - 1; j > i; j--) + { + if (arr[j].cls < arr[j - 1].cls) + { + struct Info temp = arr[j]; + arr[j] = arr[j - 1]; + arr[j - 1] = temp; + } + } + for (int i = 0; i < s; i++) + for (int j = s - 1; j > 0; j--) + { + if (arr[j].cls == arr[j - 1].cls && arr[j].sum > arr[j - 1].sum) + { + struct Info temp = arr[j]; + arr[j] = arr[j - 1]; + arr[j - 1] = temp; + } + } +} +void Scls(int s) +{ + int cl, ch; + scanf("%d-%d", &cl, &ch); + for (int i = 0; i < s; i++) + if (arr[i].cls >= cl && arr[i].cls <= ch) + Output(i); +} +void Snum(int s) +{ + char str[12]; + gets(str); + char nl[6], nh[6]; + strncpy(nl, str, 5); + for (int i = 6; i < 11; i++) + nh[i - 6] = str[i]; + for (int i = 0; i < s; i++) + if (strcmp(arr[i].num, nl) >= 0 && strcmp(arr[i].num, nh) <= 0) + Output(i); +} +void Sname(int s) +{ + char n[6]; + gets(n); + for (int i = 0; i < s; i++) + { + int f = 0; + for (int j = 0; n[j] != '*'; j++) + if (n[j] != arr[i].name[j]) + { + f = 1; + break; + } + if (f == 0) + Output(i); + } +} +void Ssum(int s) +{ + float scr; + scanf("%f", &scr); + for (int i = 0; i < s; i++) + if (arr[i].sum >= scr) + Output(i); +} +void Scn(int s) +{ + int clas; + scanf("%d.", &clas); + char str[12]; + gets(str); + char nl[6], nh[6]; + strncpy(nl, str, 5); + for (int i = 6; i < 11; i++) + nh[i - 6] = str[i]; + for (int i = 0; i < s; i++) + if (arr[i].cls == clas && strcmp(arr[i].num, nl) >= 0 && strcmp(arr[i].num, nh) <= 0) + Output(i); +} +void Seek(int s) +{ + int c; + scanf("%d ", &c); + switch (c) + { + case 1:Scls(s); break; + case 2:Snum(s); break; + case 3:Sname(s); break; + case 4:Ssum(s); break; + case 5:Scn(s); break; + }; +} +int main() +{ + int s = 0, * p = &s; + for (; s < 7; s++) + Input(s); + Rank(arr, s); + Seek(s); + +}