PAT 解题报告 1062. Talent and Virtue (25)

题目描述:

About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people’s talent and virtue. According to his theory, a man being outstanding in both talent and virtue must be a “sage(圣人)”; being less excellent but with one’s virtue outweighs talent can be called a “nobleman(君子)”; being good in neither is a “fool man(愚人)”; yet a fool man is better than a “small man(小人)” who prefers talent than virtue.

Now given the grades of talent and virtue of a group of people, you are supposed to rank them according to Sima Guang’s theory.

题目就是要求根据给出的每个人的`德`的分数和`才`的分数, 对人进行分组, 然后组内排序.

算法分析:

题目其实不难, 就是分类和排序规则复杂了一点

(1) 两个分数都 < L的不用进行排序

(注意下面开始都是两个分数 >= L的)

(2) 两个分数都 >= H的是圣人, 等级最高, 排在最前面, 内部排序用题目给出的算法, 先按总分, 再按照`德`的分数, 最后按照id

(3) 德的分数>= H, 才的分数 < H, 是第二档, 叫君子, 内部排序如上

(4) 两个分数都 < H, 但是 德的分数 >= 才的分数, 分类成愚人, 内部排序如上. 这里仔细看清题意, 不仔细的话容易把(3)反过来当成(4)

(5) 剩下的就是小人了(其他)

分类的同时统计实际排序的个数, 再按照题意输出.

注意点:

(1) 注意分类规则.

(2) 如果用int存id的话, 格式化输出的时候记得保留八位, 前面补0.

Written on September 2, 2013