diff --git a/1.c b/1.c new file mode 100644 index 0000000..985b634 --- /dev/null +++ b/1.c @@ -0,0 +1,63 @@ +#include + +struct Data +{ + int ID; + float score1; + float score2; + float score3; +} stu[1001]; +int stl = 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; +} + +void input1() { + scanf("%d", &stu[stl].ID); + scanf("%f", &stu[stl].score1); + scanf("%f", &stu[stl].score2); + scanf("%f", &stu[stl].score3); + stl++; +} + +void Question1() { + printf("Please input info of three students:\n"); + input1();input1();input1(); + printf("%d %2.1f %2.1f %2.1f %.1f\n", stu[stl-3].ID, stu[stl-3].score1, stu[stl-3].score2, stu[stl-3].score3, total(&stu[stl-3])); + printf("%d %2.1f %2.1f %2.1f %.1f\n", stu[stl-2].ID, stu[stl-2].score1, stu[stl-2].score2, stu[stl-2].score3, total(&stu[stl-2])); + printf("%d %2.1f %2.1f %2.1f %.1f\n", stu[stl-1].ID, stu[stl-1].score1, stu[stl-1].score2, stu[stl-1].score3, total(&stu[stl-1])); + +} + +int main() { + printf(" 1.Input\n"); + printf(" 2.Output\n"); + printf(" 3.Order\n"); + printf(" 4.Quit\n"); + char t; + scanf("%c", &t); + switch(t) { + case 'i': + printf("You are trying to Input info\n"); + break; + case 'o': + printf("You are trying to Output info\n"); + break; + case 'm': + printf("You are trying to Make things ordered\n"); + break; + case 'q': + printf("You are trying to Quit\n"); + break; + default: + printf("Wrong input\n"); + break; + } +} \ No newline at end of file diff --git a/2.c b/2.c new file mode 100644 index 0000000..34a9e7c --- /dev/null +++ b/2.c @@ -0,0 +1,56 @@ +#include + +struct Data +{ + int ID; + float score1; + float score2; + float score3; +} stu[1001]; +int stl = 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; +} + +void input1() { + scanf("%d", &stu[stl].ID); + scanf("%f", &stu[stl].score1); + scanf("%f", &stu[stl].score2); + scanf("%f", &stu[stl].score3); + stl++; +} + +void Question1() { + printf("Please input info of three students:\n"); + input1();input1();input1(); + printf("%d %2.1f %2.1f %2.1f %.1f\n", stu[stl-3].ID, stu[stl-3].score1, stu[stl-3].score2, stu[stl-3].score3, total(&stu[stl-3])); + printf("%d %2.1f %2.1f %2.1f %.1f\n", stu[stl-2].ID, stu[stl-2].score1, stu[stl-2].score2, stu[stl-2].score3, total(&stu[stl-2])); + printf("%d %2.1f %2.1f %2.1f %.1f\n", stu[stl-1].ID, stu[stl-1].score1, stu[stl-1].score2, stu[stl-1].score3, total(&stu[stl-1])); + +} + +void Typein() +{ + scanf("%d", &stu[stl].ID); + scanf("%f", &stu[stl].score1); + scanf("%f", &stu[stl].score2); + scanf("%f", &stu[stl].score3); + stl++; +} + +int main() { + Typein(); + Typein(); + Typein(); + printf("%d %2.1f %2.1f %2.1f %.1f\n", stu[stl-3].ID, stu[stl-3].score1, stu[stl-3].score2, stu[stl-3].score3, total(&stu[stl-3])); + printf("%d %2.1f %2.1f %2.1f %.1f\n", stu[stl-2].ID, stu[stl-2].score1, stu[stl-2].score2, stu[stl-2].score3, total(&stu[stl-2])); + printf("%d %2.1f %2.1f %2.1f %.1f\n", stu[stl-1].ID, stu[stl-1].score1, stu[stl-1].score2, stu[stl-1].score3, total(&stu[stl-1])); + +} \ No newline at end of file diff --git a/3.c b/3.c new file mode 100644 index 0000000..1311ed7 --- /dev/null +++ b/3.c @@ -0,0 +1,67 @@ +#include + +struct Data +{ + int ID; + float score1; + float score2; + float score3; +} stu[1001]; +int stl = 0, sortstl; + +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; +} + +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); +} + +int main() { + printf(" 1.Input\n"); + printf(" 2.Output\n"); + printf(" 3.Order\n"); + printf(" 4.Quit\n"); + char t; + scanf("%c", &t); + switch(t) { + case 'i': + printf("You are trying to Input info\n"); + Input(); + break; + case 'o': + printf("You are trying to Output info\n"); + break; + case 'm': + printf("You are trying to Make things ordered\n"); + break; + case 'q': + printf("You are trying to Quit\n"); + break; + default: + printf("Wrong input\n"); + break; + } +} \ No newline at end of file diff --git a/4.c b/4.c new file mode 100644 index 0000000..f6be406 --- /dev/null +++ b/4.c @@ -0,0 +1,89 @@ +#include + +struct Data +{ + int ID; + int Class; + float score1; + float score2; + float score3; +} stu[1001]; +int stl = 0; +struct Data* stuflag; + +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(struct Data* a) { + printf("%d %d %2.1f %2.1f %2.1f", a->ID, a->Class, + a->score1, a->score2, a->score3); + if (a == stuflag) printf(" inserted"); + printf("\n"); +} + +void Insert() { + stu[0] = (struct Data){10001, 11, 99.5, 88.5, 89.5}; + stu[1] = (struct Data){10002, 12, 77.9, 56.5, 87.5}; + stu[2] = (struct Data){10003, 11, 92.5, 89.0, 60.5}; + stl = 3; + + scanf("%d", &stu[stl].ID); + scanf("%d", &stu[stl].Class); + scanf("%f", &stu[stl].score1); + scanf("%f", &stu[stl].score2); + scanf("%f", &stu[stl].score3); + stl++; + + stuflag = stu + 3; + Sort(); + print1(stu + 0); + print1(stu + 1); + print1(stu + 2); + print1(stu + 3); +} + +int main() { + Insert(); +} \ No newline at end of file diff --git a/5.c b/5.c new file mode 100644 index 0000000..e2b1a4e --- /dev/null +++ b/5.c @@ -0,0 +1,112 @@ +#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(struct Data* a) { + printf("%d %d %s %2.1f %2.1f %2.1f", a->ID, a->Class, a->name, + a->score1, a->score2, a->score3); + if (a == stuflag) printf(" inserted"); + printf("\n"); +} + +void Remove(struct Data* r) { + for(; r+1 < stu+stl; r++) { + *r = *(r+1); + } + stl--; +} + +void Delete() { + 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"}; + stl = 3; + + int ID = -1; char name[101]; + scanf("%s", name); + getchar(); + int NumFlag = 1, i; + for(i = 0; name[i]!='\0'; i++) + if (name[i] < '0' || name[i] > '9') { + NumFlag = 0; break; + } + if (NumFlag) { + sscanf(name, "%d", &ID); + name[0] = '\0'; + } + + printf("Are you sure(yes/no)?\n"); + char t; + scanf("%c", &t); + if (t == 'y') { + for(i=0; i +#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 Modify() { + + struct Data t; + scanf("%d", &t.ID); + scanf("%d", &t.Class); + scanf("%s", t.name); + scanf("%f", &t.score1); + scanf("%f", &t.score2); + scanf("%f", &t.score3); + + int i; + + for(i=0; i0 && stu[i].Class == stu[i-1].Class) printf(" "); + else printf("%2d ", stu[i].Class); + printf("%d %s %2.1f %2.1f %2.1f", stu[i].ID, stu[i].name, + stu[i].score1, stu[i].score2, stu[i].score3); + if (stuflag == stu + i) printf(" modified"); + printf("\n"); + } + +} + +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"}; + stl = 3; + Modify(); +} \ No newline at end of file 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 diff --git a/8.c b/8.c new file mode 100644 index 0000000..c7bfe78 --- /dev/null +++ b/8.c @@ -0,0 +1,245 @@ +#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,%.1f\n", stu[i].ID, stu[i].Class, stu[i].name, + stu[i].score1, stu[i].score2, stu[i].score3, total(&stu[i])); +} + +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); + } + } + } +} + +void Output() { + int i; + for(i=0; i '9') { + NumFlag = 0; break; + } + if (NumFlag) { + sscanf(name, "%d", &ID); + name[0] = '\0'; + } + for(i=0; i '9') { + NumFlag = 0; break; + } + if (NumFlag) { + int num; + sscanf(com, "%d", &num); + if (strlen(com) > 2) + for (i=0; i