#include <stdio.h>
#include <string.h>

struct data{
char name[11];
char id[11];
int score[3];
};

void operation_1(struct data stu[], int, int); //add information
void operation_2(struct data stu[], int, int); //delete information
void operation_3(struct data stu[], int, int); //change information
void operation_4(struct data stu[], int, int); //average score

int main()
{
int order, i, n;
struct data stu[130];

scanf("%d", &n);
for(i = 0; i < n ; i++)
{
scanf("%d", &order);
getchar();
if(order == 1)
operation_1(stu, n, i);
else if(order == 2)
operation_2(stu, n, i);
else if(order == 3)
operation_3(stu, n, i);
else if(order == 4)
operation_4(stu, n, i);
}

return 0;
}

void operation_1(struct data stu[], int n, int i)
{
char buffer[11];//buffer
int flag = 1;
scanf("%s", &buffer);
for (int j = 0; j < n; j++)
{
if (strcmp(buffer, stu[j].id) == 0) //search
{
flag = 0;
j = 130;//equal to break
}
}
getchar();
if (flag == 1)
{
strcpy(stu[i].id, buffer);
scanf("%s%d%d%d", stu[i].name, &stu[i].score[0], &stu[i].score[1], &stu[i].score[2]);
printf("Add success\n");
}
else printf("Students already exist\n");
}

void operation_2(struct data stu[], int n, int i)
{
char buffer[11];//buffer
int flag = 1;
scanf("%s", &buffer);
for (int j = 0; j < n; j++)
{
if (strcmp(buffer, stu[j].id) == 0) //search
{
flag = 0;
stu[j]=stu[i+1];
j=130;//equal to break
}
}
getchar();
if (flag == 0)
{
printf("Delete success\n");
}
else printf("Students do not exist\n");
}

void operation_3(struct data stu[], int n, int i)
{
char buffer[11];//buffer
int flag = 1, t;
scanf("%s", &buffer);
for (int j = 0; j < n; j++)
{
if (strcmp(buffer, stu[j].id) == 0) //search
{
flag = 0;
t=j;
j=130;//equal to break
}
}
if(flag==0)
{
scanf("%d%d%d", &stu[t].score[0], &stu[t].score[1], &stu[t].score[2]);
printf("Update success\n");
}
else printf("Students do not exist\n");
}

void operation_4(struct data stu[], int n, int i)
{
char buffer[11];//buffer
int flag = 1, t;
scanf("%s", &buffer);
for (int j = 0; j < n; j++)
{
if (strcmp(buffer, stu[j].id) == 0) //search
{
flag = 0;
t=j;
j=130;//equal to break
}
}
if(flag==0)
{
printf("Student ID:%s\n", stu[t].id);
printf("Name:%s\n", stu[t].name);
printf("Average Score:%.1lf\n", (stu[t].score[0]+stu[t].score[1]+stu[t].score[2])*1.0/3);
}
else printf("Students do not exist\n");
}

Comments  

# Moderator 2021-12-23 11:05
测试数据
https://bbc3502.hopto.org/c2021/index.php/home-17/623-2021-12-23-03-04-34
# Fanjingbo 2021-12-22 21:26
样例是对的,但是零分
# Fanjingbo 2021-12-22 21:25
老师这个题不知道哪里错了,一开始以为是全局变量的问题改了之后还是不对

You have no rights to post comments