题目原文
题目描述
现在你的数据库里已经存储了以下信息:
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
Asss Dccc 202212344321 84 0 B+
Asssd Dccec 202122244321 83 0 B+
要求编写函数 void Search(long long id) 或者void Search(char * id)
根据学号返回该学生的全部查询信息。如果在数据库里没有找到该学号,则输出"Not Found."
输入
若干组数据。被搜索学生的id,0代表搜索结束。
输出
该学生的信息
如果数据库里没有改学生的信息,则输出"Not Found."
样例
输入样例1
202200100000
202200100000
0
输出样例1
Jy LEE 202200100000 89 0 A
Jy LEE 202200100000 89 0 A
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"},
{"Jingyuuuu", "LI", "202200000900", 59, 0, "F"},
{"Jingyuuuu", "Lous", "202100000900", 60, 1, "D"},
{"Asss", "Dccc", "202212344321", 84, 0, "B+"},
{"Asssd", "Dccec", "202122244321", 83, 0, "B+"}};
void Search(char *id)
{
int flag = 0;
for (int i = 0; i < 8; i++)
{
if (strcmp(id, stu[i].id) == 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);
flag = 1;
break;
}
}
if (!flag)
printf("Not Found.\n");
}
int main()
{
char id[20];
while (scanf("%s", id) && strcmp(id, "0") != 0)
{
if (strlen(id) != 12)
continue;
Search(id);
}
return 0;
}