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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/a845717607/article/details/86357237

1073 多选题常见计分法 (20 point(s))

批改多选题是比较麻烦的事情,有很多不同的计分方法。有一种最常见的计分方法是:如果考生选择了部分正确选项,并且没有选择任何错误选项,则得到 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

经验总结:

这一题...其实就是PAT 乙级 1058 选择题 的加强版,复杂了一些,关键是....有坑啊!错误选项不止是字面上的不是正确选项的选项,还有漏选的正确选项.....我愣是看输出样例1看了半天,无法得出他给出的正确输出,可以肯定的是,输出样例肯定是没错的,错的是自己的思路,不过我也实在想不到,漏选的正确选项竟然也算错误的....有违常理(我个人的常理= =),其他的就没啥难度了,就是字符串处理可能有一些复杂,想要简单的话,多使用一些STL就行啦!~( ´・∀・`)

AC代码 

#include <cstdio>
#include <vector>
#include <cstring>
#include <string>
#include <iostream>
using namespace std;
struct problem
{
	int opnum;
	int ropnum;
	int ans[6];
	int wrong[6];
	int score;
	int no;
	problem()
	{
		memset(ans,0,sizeof(ans));
		memset(wrong,0,sizeof(wrong));
	}
}p[110];
int main()
{
	int n,m,tscore,tcount,tnum;
	char x;
	string temp;
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;++i)
	{
		scanf("%d %d %d",&tscore,&tcount,&tnum);
		p[i].no=i+1;
		p[i].opnum=tcount;
		p[i].ropnum=tnum;
		p[i].score=tscore;
		for(int j=0;j<tnum;++j)
		{
			scanf(" %c",&x);
			p[i].ans[x-'a']=1;
		}
	}
	getchar();
	int maxcount=0;
	for(int i=0;i<n;++i)
	{
		double goal=0;
		getline(cin,temp);
		int k=0,tn;
		for(int j=0;j<temp.size();++j)
		{
			if(temp[j]=='(')
			{
				tn=temp[j+1]-'0';
				int pos=j+3;
				int flag=0;
				for(int s=0;s<tn;++s)
				{
					int tp=temp[pos+s+s]-'a';
					if(p[k].ans[tp]==0)
					{
						++p[k].wrong[tp];
						maxcount=max(p[k].wrong[tp],maxcount);
						flag=1;
					}
				}
				string ttemp=temp.substr(pos,tn+tn);
				for(int s=0;s<p[k].opnum;++s)
				{
					if(p[k].ans[s]==1)
					{
						if(ttemp.find(s+'a')==string::npos)
						{
							++p[k].wrong[s];
							maxcount=max(p[k].wrong[s],maxcount);
						}
					}
				}
				if(flag==0&&tn==p[k].ropnum)
					goal+=p[k].score;
				if(flag==0&&tn<p[k].ropnum)
					goal+=p[k].score*1.0/2;
				++k;
				j+=3+tn*2;
			}
		}
		printf("%.1f\n",goal);
	}
	if(maxcount==0)
		printf("Too simple\n");
	else
	{
		for(int i=0;i<m;++i)
		{
			for(int j=0;j<p[i].opnum;++j)
			{
				if(p[i].wrong[j]==maxcount)
				{
					printf("%d %d-%c\n",maxcount,p[i].no,j+'a');
				}
			}
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/a845717607/article/details/86357237