乙级的题目训练主要用来熟悉编程语言的语法和形成良好的编码习惯和编码规范。从小白开始逐步掌握用编程解决问题。
PAT (Basic Level) Practice 1077 互评成绩计算
问题分析
题设要求计算每个组的互评成绩, 并且给出了互评成绩的计算方式, 毫无疑问, 这是一道模拟题.
需要做的是明确题设给定的步骤然后翻译成代码。
完整描述步骤
获取输入: 小组数量, 满分值对于每一个小组: 获取输入: 教师评分, 其他小组给定的评分检查其他小组给定的分数是否在区间[0, 满分值]中, 仅计算合理的分数计算其他小组给定评分的总和, 最高分, 最低分计算其他小组给定评分的平均分 = (总分 - 最高分 - 最低分) / (合理分数个数 - 2)计算该小组得分 = (教师评分 + 其他小组评分平均分)/ 2输出小组得分伪代码描述
get input: group_amount, full_scorefor each group: init recorder: valid_score_amount = 0;score_sum = 0;max_score = -1;min_score = full_score + 1; get input: teacher_score, scores of other groupsfor score in scores of other groups: if score < 0 or score > full_score:continue;if score > max_score: max_score = score; if score < min_score: min_score = score; valid_score_amount++;score_sum += score;group_score_averages = (score_sum - max_score - min_score) / (valid_score_amount - 2);current_group_score = (teacher_score + group_score_averages) / 2;print(current_group_score) # in given format
完整提交代码
/*# 问题分析题设要求计算每个组的互评成绩, 并且给出了互评成绩的计算方式, 毫无疑问, 这是一道模拟题.需要做的是明确题设给定的步骤然后翻译成代码。# 完整描述步骤1. 获取输入: 小组数量, 满分值2. 对于每一个小组: - 获取输入: 教师评分, 其他小组给定的评分 - 检查其他小组给定的分数是否在区间[0, 满分值]中, 仅计算合理的分数 - 计算其他小组给定评分的总和, 最高分, 最低分 - 计算其他小组给定评分的平均分 = (总分 - 最高分 - 最低分) / (合理分数个数 - 2) - 计算该小组得分 = (教师评分 + 其他小组评分平均分)/ 2 - 输出小组得分# 伪代码描述1. get input: group_amount, full_score2. for each group: - init recorder: - valid_score_amount = 0; - score_sum = 0; - max_score = -1; - min_score = full_score + 1; - get input: teacher_score, scores of other groups - for score in scores of other groups: - if score < 0 or score > full_score: continue; - if score > max_score: - max_score = score; - if score < min_score: - min_score = score; - valid_score_amount++; - score_sum += score; - group_score_averages = (score_sum - max_score - min_score) / (valid_score_amount - 2); - current_group_score = (teacher_score + group_score_averages) / 2; - print(current_group_score) # in given format*/# include<stdio.h>int main(){ int group_amount, full_score; scanf("%d %d", &group_amount, &full_score); for (int i = 0; i < group_amount; i++){ int max_score = 0, min_score = full_score; int teacher_score; scanf("%d", &teacher_score); int valid_score_amount = 0; int group_score = 0; int score; for(int j = 1; j < group_amount; j++){ scanf("%d", &score); if (0 <= score && score <= full_score){ valid_score_amount++; group_score+=score; if (score > max_score){ max_score = score; } if (score < min_score){ min_score = score; } } } double group_score_average = (double)(group_score - max_score - min_score) / (valid_score_amount - 2); int final_score = (group_score_average + teacher_score) / 2 + 0.5; printf("%d\n", final_score); } return 0;}