Compare commits
No commits in common. 'main' and 'main' have entirely different histories.
@ -1,63 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
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]));
|
||||
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
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();
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
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<stl; i++) {
|
||||
if(stu[i].ID == ID || name[0]!='\0' && strcmp(stu[i].name, name) == 0) {
|
||||
Remove(stu + i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i=0; i<stl; i++) {
|
||||
print1(stu + i);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
Delete();
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
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; i<stl; i++) {
|
||||
if (t.ID == stu[i].ID) {
|
||||
stu[i] = t;
|
||||
stuflag = stu + i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Sort();
|
||||
for(i=0; i<stl; i++) {
|
||||
if (i>0 && 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();
|
||||
}
|
@ -1,132 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
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<stl; i++) {
|
||||
if (stu[i].Class >= from && stu[i].Class <= to)
|
||||
Print1(i);
|
||||
}
|
||||
}break;
|
||||
case 2: {
|
||||
int from, to;
|
||||
sscanf(com, "%d-%d", &from, &to);
|
||||
for (i=0; i<stl; i++) {
|
||||
if (stu[i].ID >= from && stu[i].ID <= to)
|
||||
Print1(i);
|
||||
}
|
||||
}break;
|
||||
case 3: {
|
||||
for (i=0; i<stl; i++) {
|
||||
int flag = 1, j;
|
||||
for (j=0; com[j] != '*'; j++) {
|
||||
if (stu[i].name[j] != com[j]) {
|
||||
flag = 0; break;
|
||||
}
|
||||
}
|
||||
if(flag)
|
||||
Print1(i);
|
||||
}
|
||||
}break;
|
||||
case 4: {
|
||||
float gate;
|
||||
sscanf(com, "%f", &gate);
|
||||
for (i=0; i<stl; i++) {
|
||||
if (total(stu + 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<stl; i++) {
|
||||
if (stu[i].ID >= 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();
|
||||
}
|
@ -1,245 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
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<stl; i++) {
|
||||
if (stu[i].Class >= from && stu[i].Class <= to)
|
||||
Print1(i);
|
||||
}
|
||||
}break;
|
||||
case 2: {
|
||||
int from, to;
|
||||
sscanf(com, "%d-%d", &from, &to);
|
||||
for (i=0; i<stl; i++) {
|
||||
if (stu[i].ID >= from && stu[i].ID <= to)
|
||||
Print1(i);
|
||||
}
|
||||
}break;
|
||||
case 3: {
|
||||
for (i=0; i<stl; i++) {
|
||||
int flag = 1, j;
|
||||
for (j=0; com[j] != '*'; j++) {
|
||||
if (stu[i].name[j] != com[j]) {
|
||||
flag = 0; break;
|
||||
}
|
||||
}
|
||||
if(flag)
|
||||
Print1(i);
|
||||
}
|
||||
}break;
|
||||
case 4: {
|
||||
float gate;
|
||||
sscanf(com, "%f", &gate);
|
||||
for (i=0; i<stl; i++) {
|
||||
if (total(stu + 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<stl; i++) {
|
||||
if (stu[i].ID >= from && stu[i].ID <= to)
|
||||
if (stu[i].Class == Class)
|
||||
Print1(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Output() {
|
||||
int i;
|
||||
for(i=0; i<stl; 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 Typein()
|
||||
{
|
||||
printf("Id ");
|
||||
scanf("%d", &stu[stl].ID);
|
||||
printf("class ");
|
||||
scanf("%d", &stu[stl].Class);
|
||||
printf("name ");
|
||||
scanf("%s", stu[stl].name);
|
||||
printf("score1 ");
|
||||
scanf("%f", &stu[stl].score1);
|
||||
printf("score2 ");
|
||||
scanf("%f", &stu[stl].score2);
|
||||
printf("score3 ");
|
||||
scanf("%f", &stu[stl].score3);
|
||||
stl++;
|
||||
}
|
||||
|
||||
void Delete() {
|
||||
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';
|
||||
}
|
||||
for(i=0; i<stl; i++) {
|
||||
if(stu[i].ID == ID || (name[0]!='\0' && strcmp(stu[i].name, name) == 0)) {
|
||||
struct Data* r = stu + i;
|
||||
for(; r+1 < stu+stl; r++) {
|
||||
*r = *(r+1);
|
||||
}
|
||||
stl--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Output();
|
||||
}
|
||||
|
||||
void Select_3() {
|
||||
char com[101];
|
||||
scanf("%s", com);
|
||||
int NumFlag = 1, i;
|
||||
for(i = 0; com[i]!='\0'; i++)
|
||||
if (com[i] < '0' || com[i] > '9') {
|
||||
NumFlag = 0; break;
|
||||
}
|
||||
if (NumFlag) {
|
||||
int num;
|
||||
sscanf(com, "%d", &num);
|
||||
if (strlen(com) > 2)
|
||||
for (i=0; i<stl; i++) {
|
||||
if (stu[i].Class == num)
|
||||
Print1(i);
|
||||
}
|
||||
else
|
||||
for (i=0; i<stl; i++)
|
||||
if (stu[i].ID == num)
|
||||
Print1(i);
|
||||
}
|
||||
else {
|
||||
for (i=0; i<stl; i++)
|
||||
if (strcmp(stu[i].name, com) == 0)
|
||||
Print1(i);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
char com[11];
|
||||
while(1) {
|
||||
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");
|
||||
int t; scanf("%d", &t);
|
||||
switch(t) {
|
||||
case 1:
|
||||
do{
|
||||
Typein();
|
||||
printf("continue?\n");
|
||||
scanf("%s", com);
|
||||
}while(strcmp(com, "yes") == 0);
|
||||
Sort();
|
||||
break;
|
||||
case 2:
|
||||
do {
|
||||
Delete();
|
||||
printf("continue?\n");
|
||||
scanf("%s", com);
|
||||
}while(strcmp(com, "yes") == 0);
|
||||
break;
|
||||
case 3:
|
||||
do {
|
||||
Select_3();
|
||||
printf("continue?\n");
|
||||
scanf("%s", com);
|
||||
}while(strcmp(com, "yes") == 0);
|
||||
break;
|
||||
case 4:
|
||||
Sort();
|
||||
Output();
|
||||
break;
|
||||
case 5:
|
||||
Output();
|
||||
break;
|
||||
case 6:
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,292 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct Student
|
||||
{
|
||||
char id[20];
|
||||
char class[20];
|
||||
char name[20];
|
||||
double score1;
|
||||
double score2;
|
||||
double score3;
|
||||
double score;
|
||||
|
||||
struct Student *prev;
|
||||
struct Student *next;
|
||||
}LinkList;
|
||||
|
||||
bool sorted=false;
|
||||
|
||||
typedef bool (*Linklist_cmp)(LinkList *,LinkList *);
|
||||
|
||||
bool bigger(LinkList * a,LinkList * b){
|
||||
return a->score<b->score;
|
||||
}
|
||||
|
||||
bool smallerclass_biggerscore(LinkList * a,LinkList * b){
|
||||
if(strcmp(a->class,b->class)>0){
|
||||
return 1;
|
||||
}
|
||||
else if(strcmp(a->class,b->class)==0) {
|
||||
return a->score<b->score;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
LinkList *Linklist_append(LinkList *prev) {
|
||||
LinkList *node;
|
||||
node = (LinkList *) malloc(sizeof(LinkList));
|
||||
|
||||
printf("Id ");
|
||||
scanf("%s",node->id);
|
||||
printf("class ");
|
||||
scanf("%s",node->class);
|
||||
printf("name ");
|
||||
scanf("%s",node->name);
|
||||
printf("score1 ");
|
||||
scanf("%lf",&node->score1);
|
||||
printf("score2 ");
|
||||
scanf("%lf",&node->score2);
|
||||
printf("score3 ");
|
||||
scanf("%lf",&node->score3);
|
||||
|
||||
node->score = node->score1 + node->score2 + node->score3;
|
||||
|
||||
prev->next=node;
|
||||
node->next=NULL;
|
||||
node->prev=prev;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
void Linklist_delete(LinkList *cur) {
|
||||
|
||||
if(cur->next != NULL){
|
||||
cur->next->prev=cur->prev;
|
||||
}
|
||||
cur->prev->next=cur->next;
|
||||
free(cur);
|
||||
}
|
||||
|
||||
void Linklist_swap(LinkList *s1, LinkList *s2){
|
||||
if(s1->next == s2){
|
||||
if(s2->next != NULL){
|
||||
s2->next->prev = s1;
|
||||
}
|
||||
if(s1->prev != NULL){
|
||||
s1->prev->next = s2;
|
||||
}
|
||||
s1->next = s2->next;
|
||||
s2->prev = s1->prev;
|
||||
s1->prev = s2;
|
||||
s2->next = s1;
|
||||
}else if(s1->prev == s2){
|
||||
if(s1->next != NULL){
|
||||
s1->next->prev = s2;
|
||||
}
|
||||
if(s2->prev != NULL){
|
||||
s2->prev->next = s1;
|
||||
}
|
||||
s2->next = s1->next;
|
||||
s1->prev = s2->prev;
|
||||
s2->prev = s1;
|
||||
s1->next = s2;
|
||||
}else{
|
||||
if(s1->next != NULL){
|
||||
s1->next->prev = s2;
|
||||
}
|
||||
if(s1->prev != NULL){
|
||||
s1->prev->next = s2;
|
||||
}
|
||||
if(s2->next != NULL){
|
||||
s2->next->prev = s1;
|
||||
}
|
||||
if(s2->prev != NULL){
|
||||
s2->prev->next = s1;
|
||||
}
|
||||
LinkList *s1Next = s1->next;
|
||||
LinkList *s1prev = s1->prev;
|
||||
s1->next = s2->next;
|
||||
s1->prev = s2->prev;
|
||||
s2->next = s1Next;
|
||||
s2->prev = s1prev;
|
||||
}
|
||||
}
|
||||
|
||||
void Linklist_Sort(LinkList *p,Linklist_cmp cmp){
|
||||
LinkList *head = p;
|
||||
while(head != NULL){
|
||||
LinkList *headNext = head->next;
|
||||
while(headNext != NULL){
|
||||
if(cmp(head, headNext)){
|
||||
Linklist_swap(head, headNext);
|
||||
//注意这里一定要交换下,因为改了链表节点的位置
|
||||
LinkList *tmp = head;
|
||||
head = headNext;
|
||||
headNext = tmp;
|
||||
}
|
||||
headNext = headNext->next;
|
||||
}
|
||||
head = head->next;
|
||||
}
|
||||
}
|
||||
void find_delete(LinkList * head){
|
||||
char todelatte[20];
|
||||
scanf("%s",todelatte);
|
||||
LinkList * node_ptr;
|
||||
node_ptr = head;
|
||||
while (node_ptr->next != NULL) {
|
||||
node_ptr = node_ptr->next;
|
||||
if(strcmp(todelatte,node_ptr->id)==0 || strcmp(todelatte,node_ptr->name)==0) {
|
||||
Linklist_delete(node_ptr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Linklist_Sort(head->next,bigger);
|
||||
node_ptr=head;
|
||||
while(node_ptr->next != NULL){
|
||||
node_ptr = node_ptr->next;
|
||||
printf("%s,%s,%s,%.1f,%.1f,%.1f,%.1f\n",node_ptr->id,node_ptr->class,node_ptr->name,node_ptr->score1,node_ptr->score2,node_ptr->score3,node_ptr->score);
|
||||
}
|
||||
}
|
||||
|
||||
void find(LinkList * head){
|
||||
char todelatte[20];
|
||||
scanf("%s",todelatte);
|
||||
LinkList * node_ptr;
|
||||
node_ptr = head;
|
||||
bool find_flag=false;
|
||||
while (node_ptr->next != NULL) {
|
||||
node_ptr = node_ptr->next;
|
||||
if(strcmp(todelatte,node_ptr->id)==0 || strcmp(todelatte,node_ptr->class)==0) {
|
||||
printf("%s,%s,%s,%.1f,%.1f,%.1f,%.1f\n",node_ptr->id,node_ptr->class,node_ptr->name,node_ptr->score1,node_ptr->score2,node_ptr->score3,node_ptr->score);
|
||||
find_flag = true;
|
||||
}
|
||||
}
|
||||
if(!find_flag)printf("there is no eligible student\n");
|
||||
}
|
||||
|
||||
void sort_output(LinkList * head){
|
||||
Linklist_Sort(head,smallerclass_biggerscore);//
|
||||
LinkList * node_ptr=head;
|
||||
while(node_ptr->next != NULL){
|
||||
node_ptr = node_ptr->next;
|
||||
printf("%s,%s,%s,%.1f,%.1f,%.1f,%.1f\n",node_ptr->id,node_ptr->class,node_ptr->name,node_ptr->score1,node_ptr->score2,node_ptr->score3,node_ptr->score);
|
||||
}
|
||||
}
|
||||
|
||||
void output(LinkList * head){
|
||||
if(sorted)Linklist_Sort(head,smallerclass_biggerscore);
|
||||
LinkList * node_ptr=head;
|
||||
while(node_ptr->next != NULL){
|
||||
node_ptr = node_ptr->next;
|
||||
printf("%s,%s,%s,%.1f,%.1f,%.1f,%.1f\n",node_ptr->id,node_ptr->class,node_ptr->name,node_ptr->score1,node_ptr->score2,node_ptr->score3,node_ptr->score);
|
||||
}
|
||||
}
|
||||
|
||||
void print_options(){
|
||||
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");
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
LinkList *head,*cur_node;//定义头节点,普通节点,尾部节点;
|
||||
head = (LinkList*)malloc(sizeof(LinkList));//分配地址
|
||||
head->prev=NULL;
|
||||
|
||||
/*
|
||||
LinkList wang={"1003","11","wang",1,2,3,6,head,NULL};
|
||||
LinkList zhang={"1002","22","zhang",3,2,3,8,&wang,NULL};
|
||||
LinkList li={"1001","11","li",1,4,3,9,&zhang,NULL};
|
||||
head->next=&wang;
|
||||
wang.next=&zhang;
|
||||
zhang.next= &li;
|
||||
*/
|
||||
|
||||
|
||||
while(1){
|
||||
print_options();
|
||||
rewind(stdin);
|
||||
int op = getchar();
|
||||
switch(op){
|
||||
case '1':{
|
||||
cur_node = Linklist_append(head);
|
||||
printf("\r\ncontinue?\r\n");
|
||||
rewind(stdin);
|
||||
int yn = getchar();
|
||||
while(yn != 'n'){
|
||||
cur_node = Linklist_append(cur_node);
|
||||
printf("\r\ncontinue?\r\n");
|
||||
rewind(stdin);
|
||||
yn=getchar();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case '2':{
|
||||
find_delete(head);
|
||||
printf("\r\ncontinue?\r\n");
|
||||
rewind(stdin);
|
||||
int yn = getchar();
|
||||
while(yn != 'n'){
|
||||
find_delete(head);
|
||||
printf("\r\ncontinue?\r\n");
|
||||
rewind(stdin);
|
||||
yn=getchar();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case '3':{
|
||||
find(head);
|
||||
printf("\r\ncontinue?\r\n");
|
||||
rewind(stdin);
|
||||
int yn = getchar();
|
||||
while(yn != 'n'){
|
||||
find(head);
|
||||
printf("\r\ncontinue?\r\n");
|
||||
rewind(stdin);
|
||||
yn=getchar();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case '4':{
|
||||
///make sure to run this code under ucrt64 but not mingw64!
|
||||
sort_output(head);
|
||||
printf("\r\ncontinue?\r\n");
|
||||
rewind(stdin);
|
||||
int yn = getchar();
|
||||
while(yn != 'n'){
|
||||
sort_output(head);
|
||||
printf("\r\ncontinue?\r\n");
|
||||
rewind(stdin);
|
||||
yn=getchar();
|
||||
}
|
||||
sorted = true;
|
||||
break;
|
||||
}
|
||||
case '5':{
|
||||
output(head);
|
||||
printf("\r\ncontinue?\r\n");
|
||||
rewind(stdin);
|
||||
int yn = getchar();
|
||||
while(yn != 'n'){
|
||||
output(head);
|
||||
printf("\r\ncontinue?\r\n");
|
||||
rewind(stdin);
|
||||
yn=getchar();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue