1058. 选择题(20) PAT乙级真题

1058. 选择题(20)

批改多选题是比较麻烦的事情,本题就请你写个程序帮助老师批改多选题,并且指出哪道题错的人最多。

输入格式:

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

输出格式:

按照输入的顺序给出每个学生的得分,每个分数占一行。注意判题时只有选择全部正确才能得到该题的分数。最后一行输出错得最多的题目的错误次数和编号(题目按照输入的顺序从1开始编号)。如果有并列,则按编号递增顺序输出。数字间用空格分隔,行首尾不得有多余空格。如果所有题目都没有人错,则在最后一行输出“Too simple”。

输入样例:
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) (2 b d) (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) (2 b c) (4 a b c d)
输出样例:
3
6
5
2 2 3 4
我这道题是按照题目要求来定义结构体的,然后根据要求标记、比对,累加,建议将几个功能分别写函数,不然主程序会很长,可读性很低,下面是我的代码:
#include<stdio.h>



struct choice
{
    int score;
    int trues;
    int c[5];
    int wn;
}Choice[101];
void input1(struct choice *Choice,int m);
void input2(struct choice *Choice,int n,int m,int *max);
void output(const struct choice *Choice,int *max,int m);


int main(void)
{
    int n,m;
    int max=0;
    scanf("%d %d",&n,&m);
    input1(&Choice[0],m);
    input2(&Choice[0],n,m,&max);
    if (max!=0) printf("%d",max);
    output(&Choice[0],&max,m);
    return 0;
}


void input1(struct choice *Choice,int m)
{
    int i,j,s1,k;
    char c;
    for (i=0;i<m;i++)
    {
        scanf("%d %d %d ",&Choice[i].score,&j,&k);
        Choice[i].wn=0;
        Choice[i].trues=k;
        for (s1=j-1;s1<5;s1++)
        {
            Choice[i].c[s1]=-1;
        }
        for (j--;j>=0;j--)
        {
            Choice[i].c[j]=0;
        }
        for (;k>0;k--)
        {
            scanf("%c%*c",&c);
            Choice[i].c[c-'a']=1;
        }
    }
}


void input2(struct choice *Choice,int n,int m,int *max)
{
    int i,j,k,f,k1;
    int s;
    char c;
    for (i=0;i<n;i++)
    {
        s=0;
        for (j=0;j<m;j++)
        {
            f=1;
            scanf("%*c%d%*c",&k1);
            for (k=k1;k>0;k--)
            {
                scanf("%c%*c",&c);
                if (Choice[j].c[c-'a']!=1) f=0;
            }
            if (f==1 && k1==Choice[j].trues) s+=Choice[j].score;
            else
            {
                Choice[j].wn++;
                if (*max<Choice[j].wn) *max=Choice[j].wn;
            }
            getchar();
        }
        printf("%d\n",s);
    }
}


void output(const struct choice *Choice,int *max,int m)
{
    int i;
    if (*max==0)
    {
        printf("Too simple");
    }
    else
    {
        for (i=0;i<m;i++)
        {
            if (*max==Choice[i].wn)
            printf(" %d",i+1);
        }
    }
    printf("\n");
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值