A Typical Homework (a.k.a 师兄帮帮忙)
题意翻译
_嗨,我是一名外国语学院的本科生。你知道的,C 语言编程是我们大学的必修课,即使他 / 她的专业与计算机科学毫不相关。我一点也不喜欢这门课,因为我不擅长使用电脑,而且我甚至不想尝试任何编程!但我必须做作业才能及格 :( 嘘……你能帮帮我吗?请保密!!我知道你不会对一个可怜的小女孩说“不”的,对吧,伙计?:)_
#### 任务
编写一个学生成绩管理系统(Student Performance Management System,SPMS)。
#### 概念
在 SPMS 中,最多有 $100$ 名学生,每个学生都有一个 SID、一个 CID、一个姓名和四科分数(语文、数学、英语和编程)。
- SID(student ID,即学生 ID)是一个 $10$ 位数字。
- CID(class ID,即班级 ID)是一个不大于 $20$ 的正整数。
- 姓名是一个不超过 $10$ 个字母和数字的字符串,以大写字母开头。注意姓名中不能包含空格字符。
- 每科分数都是一个不大于 $100$ 的非负整数。
#### 主菜单
当您进入学生成绩管理系统(SPMS)时,主菜单应显示如下:
$\begin{aligned}
&\texttt{Welcome to Student Performance Management System (SPMS).}
\\[-1mm] &
\\[-1mm] &\texttt{1 - Add}
\\[-1mm] &\texttt{2 - Remove}
\\[-1mm] &\texttt{3 - Query}
\\[-1mm] &\texttt{4 - Show ranking}
\\[-1mm] &\texttt{5 - Show Statistics}
\\[-1mm] &\texttt{0 - Exit} \end{aligned}$
#### 添加学生
如果您从主菜单中选择 $1$,则应在屏幕上打印以下消息:
$\texttt{Please enter the SID, CID, name and four scores. Enter 0 to finish.}$
然后程序应等待用户输入。输入的行始终有效(没有无效的 SID、CID 或姓名,且总是有四科分数等),但是 SID 可能已经存在。在这种情况下,忽略这一行并打印以下内容:
$\texttt{Duplicated SID.}$
另一方面,多个学生可以有相同的姓名。
您应继续打印上面的消息,直到用户输入一个单独的零为止。然后再次打印主菜单。
#### 删除学生
如果您从主菜单中选择 $2$,则应在屏幕上打印以下消息:
$\texttt{Please enter SID or name. Enter 0 to finish.}$
然后程序应等待用户输入,并移除数据库中所有匹配该 SID 或姓名的学生,并打印以下消息(可能出现 $xx = 0$ 的情况):
$xx\texttt{ student(s) removed.}$
您应继续打印上面的消息,直到用户输入一个单独的零为止。然后再次打印主菜单。
#### 查询学生
如果您从主菜单中选择 $3$,则应在屏幕上打印以下消息:
$\texttt{Please enter SID or name. Enter 0 to finish.}$
然后程序应等待用户输入。如果没有学生匹配该 SID 或姓名,则不做任何操作;否则,打印出所有匹配的学生,按他们添加到数据库的相同顺序显示。格式类似于“添加学生”的输入格式,但会增加 $3$ 列:排名(第 $1$ 列)、总分和平均分(最后两列)。总分最高的学生(考虑所有课程)为第 $1$ 名。如果有两个学生并列第 $2$ 名,那么下一个学生排名应为第 $4$ 名。
您应继续打印上面的消息,直到用户输入一个单独的零为止。然后再次打印主菜单。
#### 显示排名列表
如果您从主菜单中选择 $4$,则应在屏幕上打印以下消息:
$\texttt{Showing the ranklist hurts students' self-esteem. Don't do that.}$
(译者注:原题 PDF 中此消息的单引号是中文全角的,而能 AC 的格式是英文的半角引号,已在译文中更改。)
然后再次打印主菜单。
#### 显示统计信息
如果您从主菜单中选择 $5$,请按以下格式显示统计信息:
$\texttt{Please enter class ID, 0 for the whole statistics.}$
当输入 CID 时,打印以下统计信息。注意“及格”(passed)意味着成绩至少为 $60$ 分。
$
\begin{aligned}
&\texttt{Chinese}
\\[-1mm] &\texttt{Average Score: }xx.xx
\\[-1mm] &\texttt{Number of passed students: }xx
\\[-1mm] &\texttt{Number of failed students: }xx
\\[-1mm] &
\\[-1mm] &\texttt{Mathematics}
\\[-1mm] &\texttt{Average Score: }xx.xx
\\[-1mm] &\texttt{Number of passed students: }xx
\\[-1mm] &\texttt{Number of failed students: }xx
\\[-1mm] &
\\[-1mm] &\texttt{English}
\\[-1mm] &\texttt{Average Score: }xx.xx
\\[-1mm] &\texttt{Number of passed students: }xx
\\[-1mm] &\texttt{Number of failed students: }xx
\\[-1mm] &
\\[-1mm] &\texttt{Programming}
\\[-1mm] &\texttt{Average Score: }xx.xx
\\[-1mm] &\texttt{Number of passed students: }xx
\\[-1mm] &\texttt{Number of failed students: }xx
\\[-1mm] &
\\[-1mm] &\texttt{Overall:}
\\[-1mm] &\texttt{Number of students who passed all subjects: }xx
\\[-1mm] &\texttt{Number of students who passed 3 or more subjects: }xx
\\[-1mm] &\texttt{Number of students who passed 2 or more subjects: }xx
\\[-1mm] &\texttt{Number of students who passed 1 or more subjects: }xx
\\[-1mm] &\texttt{Number of students who failed all subjects: }xx
\end{aligned}
$
然后再次打印主菜单。
#### 退出 SPMS
如果您从主菜单中选择 $0$,程序应终止。
请注意,课程分数和总分应格式化为整数,但平均分应格式化为小数点后恰好两位的实数。
### 输入格式
单一的测试用例,以在主菜单屏幕输入零结束。所有输入都是有效的。输入的大小不超过 10KB。
### 输出格式
按照问题描述中所述打印出所有内容。您应该能够在您的机器上通过键盘和屏幕操作这个小程序。然而,当输入和输出没有像在键盘 - 屏幕这种情况下那样交替显示时,它们看起来可能有些滑稽。
#### 提示:
在格式化像平均分这样的浮点数时,为了防止浮点误差,一个好的方法是添加一个很小的数(在这个问题中,比如 1e-5)。否则,如果浮点误差导致结果为 $80.31499999\dots$,那么 $80.315$ 就会被输出为 $80.31$。
---
Translated by User 735713.
题目描述
[problemUrl]: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=279&page=show_problem&problem=3843
[PDF](https://uva.onlinejudge.org/external/124/p12412.pdf)
![](https://cdn.luogu.com.cn/upload/vjudge_pic/UVA12412/7b151e0fc93844bb64b77a03e02d19d07f170241.png)
输入输出格式
输入格式
![](https://cdn.luogu.com.cn/upload/vjudge_pic/UVA12412/73431faf6ab23dec35002dff2dd0f2c74ec2194d.png)
输出格式
![](https://cdn.luogu.com.cn/upload/vjudge_pic/UVA12412/4f1545d31911e6d31c075e45929f73262b50c6fc.png)
输入输出样例
输入样例 #1
1
0011223344 1 John 79 98 91 100
0022334455 1 Tom 59 72 60 81
0011223344 2 Alice 100 100 100 100
2423475629 2 John 60 80 30 99
0
3
0022334455
John
0
5
1
2
0011223344
0
5
0
4
0
输出样例 #1
Welcome to Student Performance Management System (SPMS).
1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit
Please enter the SID, CID, name and four scores. Enter 0 to finish.
Please enter the SID, CID, name and four scores. Enter 0 to finish.
Please enter the SID, CID, name and four scores. Enter 0 to finish.
Duplicated SID.
Please enter the SID, CID, name and four scores. Enter 0 to finish.
Please enter the SID, CID, name and four scores. Enter 0 to finish.
Welcome to Student Performance Management System (SPMS).
1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit
Please enter SID or name. Enter 0 to finish.
2 0022334455 1 Tom 59 72 60 81 272 68.00
Please enter SID or name. Enter 0 to finish.
1 0011223344 1 John 79 98 91 100 368 92.00
3 2423475629 2 John 60 80 30 99 269 67.25
Please enter SID or name. Enter 0 to finish.
Welcome to Student Performance Management System (SPMS).
1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit
Please enter class ID, 0 for the whole statistics.
Chinese
Average Score: 69.00
Number of passed students: 1
Number of failed students: 1
Mathematics
Average Score: 85.00
Number of passed students: 2
Number of failed students: 0
English
Average Score: 75.50
Number of passed students: 2
Number of failed students: 0
Programming
Average Score: 90.50
Number of passed students: 2
Number of failed students: 0
Overall:
Number of students who passed all subjects: 1
Number of students who passed 3 or more subjects: 2
Number of students who passed 2 or more subjects: 2
Number of students who passed 1 or more subjects: 2
Number of students who failed all subjects: 0
Welcome to Student Performance Management System (SPMS).
1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit
Please enter SID or name. Enter 0 to finish.
1 student(s) removed.
Please enter SID or name. Enter 0 to finish.
Welcome to Student Performance Management System (SPMS).
1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit
Please enter class ID, 0 for the whole statistics.
Chinese
Average Score: 59.50
Number of passed students: 1
Number of failed students: 1
Mathematics
Average Score: 76.00
Number of passed students: 2
Number of failed students: 0
English
Average Score: 45.00
Number of passed students: 1
Number of failed students: 1
Programming
Average Score: 90.00
Number of passed students: 2
Number of failed students: 0
Overall:
Number of students who passed all subjects: 0
Number of students who passed 3 or more subjects: 2
Number of students who passed 2 or more subjects: 2
Number of students who passed 1 or more subjects: 2
Number of students who failed all subjects: 0
Welcome to Student Performance Management System (SPMS).
1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit
Showing the ranklist hurts students' self-esteem. Don't do that.
Welcome to Student Performance Management System (SPMS).
1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit