PAT 乙級 1073 多選題常見計分法
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;
}