美文网首页工作生活
*PAT 1058 选择题 (20 分)

*PAT 1058 选择题 (20 分)

作者: 昭明ZMing | 来源:发表于2019-07-02 23:13 被阅读0次
#include <stdio.h>
struct prob{
    int score;
    int answer; /* bitwise storage for at most 5 options */
    int wrong;
} probs[100];

/* read 'count option1 ...' format */
int readanswer()
{
    char c;
    int count, answer = 0;
    scanf("%d", &count);
    for(int k = 0; k < count; k++)
    {
        while((c = getchar()) == ' ') ;
        answer |= 1 << (c - 'a');//按位或
    }
    return answer;
}
int main()
{
    int N, M, max = 0, useless;
    /* read the answers for each problem */
    scanf("%d %d", &N, &M);
    for(int i = 0; i < M; i++)
    {
        scanf("%d %d", &probs[i].score, &useless);
        probs[i].wrong = 0;
        probs[i].answer = readanswer();
    }
    /* read every student's answer */
    for(int i = 0; i < N; i++)
    {
        int score = 0;
        for(int j = 0; j < M; j++)
        {
            /* read answer for one problem */
            while(getchar() != '(');
            if(readanswer() == probs[j].answer) /* If it is right */
                score += probs[j].score;
            else if(max < ++probs[j].wrong)  /* If most students got it wrong */
                max = probs[j].wrong;
            while(getchar() != ')');
        }
        printf("%d\n", score);
    }
    if(max == 0)
        printf("Too simple");
    else
    {
        printf("%d", max);
        for(int i = 0; i < M; i++) 
            if(probs[i].wrong == max)
                printf(" %d", i + 1);
    }
    return 0;
}

相关文章

网友评论

    本文标题:*PAT 1058 选择题 (20 分)

    本文链接:https://www.haomeiwen.com/subject/ijvxhctx.html