PAT (Basic Level) Practice (中文)1073 多选题常见计分法 (C语言)

程序员入门水平,贴出代码大家一起进步!

题目

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

思路||总结

  1. 正确答案和学生的答案用5个单位的数组来表示,默认为0,选择则置为1。
  2. 学生的答案每行进行输入,对每个答案设置一个处理函数(见代码),每行的输入要足够大,不然最后一个测试点会出现“运行时错误”。
  3. 对于答案错误数量的统计用一维数组来表示,便于最后进行排序和输出。

AC代码

#include <stdio.h>
#include <stdlib.h>
#define NUM 5
typedef struct//正确答案结构。 
	{
	float score;
	int choices;
	int choice;
	int num[NUM];
	}correctanswer;
typedef struct//学生答案结构。 
	{
	int num;
	int x;
	int y;
	}node;
int main()
{
	int comp(const void *a,const void *b);
	float Bit(int answer[NUM],int student[NUM]);
	void Select(char *head,char *rear,int num[NUM]);
	int i,j,N,M;
	scanf("%d %d",&N,&M);//N人M道。 
	correctanswer answer[M],*p;
	p=(correctanswer*)answer;
	for(i=0;i<M;i++)
		{
		for(j=0;j<NUM;j++)answer[i].num[j]=0; 
		scanf("%f %d %d ",&answer[i].score,&answer[i].choices,&answer[i].choice);
		char t;
		t=getchar();
		while(t!='\n')
			{
			if(isalpha(t))answer[i].num[t-'a']=1;
			t=getchar();		
			};
		};
	node sign[NUM*M];//统计每道题错误情况。 
	for(i=0;i<NUM*M;i++)sign[i].num=0;
	float score[N];//统计学生成绩。
	for(i=0;i<N;i++)//处理每个学生的成绩。 
		{
		score[i]=0;
		char str[934],*head,*rear;
		gets(str);
		rear=str;
		head=rear;
		for(j=0;j<M;j++)//处理每道题目的情况。
			{
			while(*head!='(')head++;
			while(*rear!=')')rear++;
			int t,ans[NUM];
			for(t=0;t<NUM;t++)ans[t]=answer[j].num[t];
			int tem[NUM]={0};
			Select(head,rear,tem);
			float b;
			b=Bit(ans,tem);//得分比重。
			score[i]+=b*answer[j].score;
			for(t=0;t<NUM;t++)
				if(ans[t]!=tem[t])
					{
					sign[NUM*j+t].num+=1;//错误标志加1。
					sign[NUM*j+t].x=j;
					sign[NUM*j+t].y=t;
					};
			rear++;
			head=rear;
			};
		printf("%.1f\n",score[i]);
		};
	qsort(sign,NUM*M,sizeof(node),comp);
	int max=sign[0].num;
	if(max==0)puts("Too simple");
	else
		{
		node *p;
		p=(node*)sign;
		while(max==sign[0].num)
			{
			printf("%d %d-%c\n",max,(p->x)+1,(p->y)+'a');
			p++;
			max=p->num;
			}
		};
	return 0;
}
float Bit(int answer[NUM],int student[NUM])
	{
	int i,a=0,b=0,c=0;
	float flag;
	for(i=0;i<NUM;i++)
		{
		if(answer[i]==1&&student[i]==1)a++;
		else if(answer[i]==0&&student[i]==1)b++;
		else if(answer[i]==1&&student[i]==0)c++;
		};
	if(b>0)flag=0;
	else if(c>0)flag=0.5;
	else flag=1;
	return flag;
	}
void Select(char *head,char *rear,int num[NUM])
	{
	while(head<rear)
		{
		char c=*head;
		if(isalpha(c))num[c-'a']=1
		head++;
		};
	}
int comp(const void *a,const void *b)
	{
	int flag=0;
	if((((node*)b)->num)-(((node*)a)->num)>0)flag=1;
	else if((((node*)b)->num)-(((node*)a)->num)<0)flag=-1;
	else if((((node*)b)->x)-(((node*)a)->x)>0)flag=-1;
	else if((((node*)b)->x)-(((node*)a)->x)<0)flag=1;
	else if((((node*)b)->y)-(((node*)a)->y)>0)flag=-1;
	else if((((node*)b)->y)-(((node*)a)->y)<0)flag=1;
	return flag;
	}
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值