题目原文
题目描述
现在你的数据库里已经存储了以下信息:
Name_f Name_l stu_id score retake GPA
Jingyu LI 202200000000 85 0 A
Jy LEE 202200100000 89 0 A
Jxxxyx Leeeee 202100100000 100 1 A+
Jingyu11 LI 202200000001 85 0 A
根据id删除学生的成绩信息,输出新的数据库和学生总数。
要求编写函数 Delete(id)
输入
若干个被删除学生的id
输出
新的成绩表
样例
输入样例1
202200000000
202200000001
输出样例1
Name_f Name_l stu_id score retake GPA
Jy LEE 202200100000 89 0 A
Jxxxyx Leeeee 202100100000 100 1 A+
Total: 2
AC代码
#include <stdio.h>
#include <string.h>
struct Information
{
char first_name[20];
char last_name[20];
char id[20];
int score;
int retake;
char GPA[5];
} stu[110] = {
{"Jingyu", "LI", "202200000000", 85, 0, "A"},
{"Jy", "LEE", "202200100000", 89, 0, "A"},
{"Jxxxyx", "Leeeee", "202100100000", 100, 1, "A+"},
{"Jingyu11", "LI", "202200000001", 85, 0, "A"}};
int Delete(char id[])
{
for (int i = 0; i < 4; i++)
{
if (strcmp(stu[i].id, id) == 0)
{
strcpy(stu[i].id, "\0");
return 1;
}
}
return 0;
}
int main()
{
printf("Name_f Name_l stu_id score retake GPA\n");
char id[20];
int i = 4;
while (~scanf("%s", id))
{
if (strlen(id) != 12)
continue;
if (Delete(id))
i--;
}
for (int i = 0; i < 4; i++)
{
if (strcmp(stu[i].id, "\0") != 0)
printf("%s %s %s %d %d %s\n", stu[i].first_name, stu[i].last_name, stu[i].id, stu[i].score, stu[i].retake, stu[i].GPA);
}
printf("Total: %d", i);
return 0;
}