题目原文
题目描述
现在你的数据库里已经存储了以下信息:
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
追加若干个学生的成绩信息,输出新的数据库和学生总数。
要求编写函数 Add(name_f, name_l, id, score)
输入
追加信息
输出
新的成绩表
样例
输入样例1
Jingyuuuu LI 202200000900 59
Jingyuuuu Lous 202100000900 60
输出样例1
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
Jingyuuuu LI 202200000900 59 0 F
Jingyuuuu Lous 202100000900 60 1 D
Total: 6
提示
需要过滤掉不合法输入:成绩不在0~100区间内的;学号不是12位的。
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"}};
char gpa[][5] = {{""}, {"A+"}, {"A"}, {"B+"}, {"B"}, {"C+"}, {"C"}, {"D"}, {"F"}};
char check_id[] = {"2022"};
void get_gpa(int i)
{
if (stu[i].score >= 93)
strcpy(stu[i].GPA, "A+");
else if (stu[i].score >= 85)
strcpy(stu[i].GPA, "A");
else if (stu[i].score >= 80)
strcpy(stu[i].GPA, "B+");
else if (stu[i].score >= 75)
strcpy(stu[i].GPA, "B");
else if (stu[i].score >= 70)
strcpy(stu[i].GPA, "C+");
else if (stu[i].score >= 65)
strcpy(stu[i].GPA, "C");
else if (stu[i].score >= 60)
strcpy(stu[i].GPA, "D");
else
strcpy(stu[i].GPA, "F");
}
void init()
{
printf("Name_f Name_l stu_id score retake GPA\n");
printf("Jingyu LI 202200000000 85 0 A\n");
printf("Jy LEE 202200100000 89 0 A\n");
printf("Jxxxyx Leeeee 202100100000 100 1 A+\n");
printf("Jingyu11 LI 202200000001 85 0 A\n");
}
void Add(char name_f[], char name_l[], char id[], int score, int i)
{
strcpy(stu[i].first_name, name_f);
strcpy(stu[i].last_name, name_l);
strcpy(stu[i].id, id);
stu[i].score = score;
}
int main()
{
init();
char name_f[20], name_l[20], id[20];
int score;
int i = 4;
while (~scanf("%s%s%s%d", name_f, name_l, id, &score))
{
if (strlen(id) != 12 || score < 0 || score > 100)
continue;
Add(name_f, name_l, id, score, i);
get_gpa(i);
if (memcmp(stu[i].id, check_id, 4) != 0)
stu[i].retake = 1;
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);
i++;
}
printf("Total: %d", i);
return 0;
}