pat 乙级1073 多选题常见计分法

发布于:2025-02-11 ⋅ 阅读:(79) ⋅ 点赞:(0)

批改多选题是比较麻烦的事情,有很多不同的计分方法。有一种最常见的计分方法是:如果考生选择了部分正确选项,并且没有选择任何错误选项,则得到 50% 分数;如果考生选择了任何一个错误的选项,则不能得分。本题就请你写个程序帮助老师批改多选题,并且指出哪道题的哪个选项错的人最多。

输入格式:

输入在第一行给出两个正整数 N(≤1000)和 M(≤100),分别是学生人数和多选题的个数。随后 M 行,每行顺次给出一道题的满分值(不超过 5 的正整数)、选项个数(不少于 2 且不超过 5 的正整数)、正确选项个数(不超过选项个数的正整数)、所有正确选项。注意每题的选项从小写英文字母 a 开始顺次排列。各项间以 1 个空格分隔。最后 N 行,每行给出一个学生的答题情况,其每题答案格式为 (选中的选项个数 选项1 ……),按题目顺序给出。注意:题目保证学生的答题情况是合法的,即不存在选中的选项数超过实际选项数的情况。另一方面,题目也保证选中的选项个数是正整数。

输出格式:

按照输入的顺序给出每个学生的得分,每个分数占一行,输出小数点后 1 位。最后输出错得最多的题目选项的信息,格式为:错误次数 题目编号(题目按照输入的顺序从1开始编号)-选项号。如果有并列,则每行一个选项,按题目编号递增顺序输出;再并列则按选项号递增顺序输出。行首尾不得有多余空格。如果所有题目都没有人错,则在最后一行输出 Too simple

输入样例 1:

3 4 
3 4 2 a c
2 5 1 b
5 3 2 b c
1 5 4 a b d e
(2 a c) (3 b d e) (2 a c) (3 a b e)
(2 a c) (1 b) (2 a b) (4 a b d e)
(2 b d) (1 e) (1 c) (4 a b c d)

输出样例 1:

3.5
6.0
2.5
2 2-e
2 3-a
2 3-b

输入样例 2:

2 2 
3 4 2 a c
2 5 1 b
(2 a c) (1 b)
(2 a c) (1 b)

输出样例 2:

5.0
5.0
Too simple

 实在惭愧,这道题断断续续居然写了一天,刚开始使用cin读取答案选项,后来改为getline.之后卡到这里如果有并列,则每行一个选项,按题目编号递增顺序输出;再并列则按选项号递增顺序输出

没有一点思路,后来参考网上,使用二位数组 来统计错误次数,及错误选项。

之后一直卡到测试点4,错误原因居然是子字符串判断错误, 举例 abd居然不能用abcd字符串的find函数判断。

我的代码修改后如下

#include <iostream>
#include<vector>
#include<iomanip>
#include<string>
using namespace std;
int cnt[100][5];
struct ques
{
	int score;
	int totalItem;
	int correctItemCount;
	string correctItem;
};
struct answer
{
	float getscore = 0;
};
int main()
{
	int n, m;
	ques question[1000];
	cin >> n >> m;

	for (int i = 0; i < m; i++)
	{
		cin >> question[i].score >> question[i].totalItem >> question[i].correctItemCount;

		string item;
		string item1;
		getline(cin, item);
		for (const auto& p : item)
		{
			if (p >= 'a' && p <= 'z')
			{
				item1 += p;
			}
		}
		question[i].correctItem = item1;
	}
	cin.ignore();
	answer answerQuestion[1000];
	for (int i = 0; i < n; i++)
	{
		string item;
		string itemOrigin;
		getline(cin, itemOrigin);
		int num = 0;
		for (int k = 0; k < itemOrigin.size(); k++)
		{
			if (itemOrigin[k] >= 'a' && itemOrigin[k] <= 'e')
			{
				item += itemOrigin[k];
			}
			if (itemOrigin[k] == ')')
			{
				if (item == question[num].correctItem)
				{
					
					answerQuestion[i].getscore += question[num].score;
				}
				else 
				{
					int length=0;
					for (auto _item : item)
					{
						if (question[num].correctItem.find(_item) !=-1)
						{
							
							length++;
						}
					}
					if (length==item.size())
					{
						answerQuestion[i].getscore += 1.0 * question[num].score / 2;
						for (int j = 0; j < 5; j++)
						{
							if (question[num].correctItem.find('a' + j) != -1 && item.find('a' + j) == -1)
							{
								cnt[num][j]++;
							}
						}
					}
					else
					{
						for (int j = 0; j < 5; j++)
						{
							if (question[num].correctItem.find('a' + j) != -1 && item.find('a' + j) == -1)
							{
								cnt[num][j]++;
							}
							if (question[num].correctItem.find('a' + j) == -1 && item.find('a' + j) != -1)
							{
								cnt[num][j]++;
							}
						}
					}
				}
				num++;
				item = "";
			}
		}
			cout << fixed << setprecision(1) << answerQuestion[i].getscore << endl;;
	}
	string test = "abcd";
	string test1 = "abc";
	int a = test.find(test1);
	int ans = 0;
	for (int i = 0; i < m; i++)
	{
		for (int k = 0; k < 5; k++)
		{
			if (cnt[i][k] > ans)
			{
				ans = cnt[i][k];
			}
		}
	}
	if (ans)
	{
		for (int i = 0; i < m; i++)
		{
			for (int k = 0; k < 5; k++)
			{
				if (cnt[i][k] == ans)
				{
					int result = 'a' + k;
					cout << cnt[i][k] << " " << i + 1 << "-" << (char)result << endl;
				}
			}
		}
	}
	else
	{
		cout << "Too simple" << endl;
	}
}


网站公告

今日签到

点亮在社区的每一天
去签到