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

这道题比1058难一些,输入的时候都是用getchar()来吸收空格和括号,并且输入题目信息的时候,选项个数和正确选项个数都没啥用,然后处理的时候,还是用的vector,如果两个相等,那么就是全对,如果不全对,接下来需要一个bool函数,传进去标准答案和学生答案,双重循环,如果有学生答案和标准答案相同的,那么两个都删除这个选项,循环完如果是,学生答案没了,标准答案个数还不为0,那么就是得一半分,先把judge的值设好,然后还需要一个处理函数,对学生答案和标准答案里面的错误选项计数,最后返回输出即可。

#include <cstdio>
#include <vector>
using namespace std;
struct answer{
    int score;
    vector<char> v;
}ans[110];
int wrong[110][5] = {}, Max = 0;
void math(int x, vector<char> v)
{
    for(int i = 0; i < v.size(); i++){
        wrong[x][v[i] - 'a']++;
        if(wrong[x][v[i] - 'a'] > Max) Max = wrong[x][v[i] - 'a'];
    }
}
bool deal(int x, vector<char> temp, vector<char> v)
{
    bool judge;
    for(int i = temp.size() - 1; i >= 0; i--){
        for(int j = 0; j < v.size(); j++){
            if(temp[i] == v[j]){
                temp.erase(temp.begin() + i);
                v.erase(v.begin() + j);
                break;
            }
        }
    }
    if(!temp.size() && v.size()) judge = true;
    else judge = false;
    math(x, temp), math(x, v);
    return judge;
}
int main()
{
    int n, m, c1, c2, num;
    char c, str[10] = "abcde";
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= m; i++){
        scanf("%d%d%d", &ans[i].score, &c1, &c2);
        for(int j = 0; j < c2; j++){
            getchar();
            scanf("%c", &c);
            ans[i].v.push_back(c);
        }
    }
    for(int i = 0; i < n; i++){
        getchar();
        double sum = 0;
        for(int j = 1; j <= m; j++){
            getchar();
            vector<char> temp;
            scanf("%d", &num);
            for(int k = 0; k < num; k++){
                getchar();
                scanf("%c", &c);
                temp.push_back(c);
            }
            if(temp == ans[j].v) sum += ans[j].score;
            else if(deal(j, temp, ans[j].v) == true) sum += ans[j].score * 1.0 / 2;
            if(j < m) getchar(), getchar();
            else getchar();
        }
        printf("%.1f\n", sum);
    }
    if(!Max) printf("Too simple");
    else{
        for(int i = 1; i <= m; i++){
            for(int j = 0; j < 5; j++){
                if(wrong[i][j] == Max){
                    printf("%d %d-%c\n", Max, i, str[j]);
                }
            }
        }
    }
    return 0;
}
发布了30 篇原创文章 · 获赞 0 · 访问量 379

猜你喜欢

转载自blog.csdn.net/qq_33942309/article/details/104489271