-1058選択PAT B(20分)

リンクをクリックして、完全なソリューションの概要PAT B -AC

タイトル:
マーキング、複数の選択肢がもっと面倒なことで、この質問は、複数の選択肢の質問をマークし、ヘルプの先生にプログラムを書くことを尋ね、そしてどのようなほとんどの人に間違った質問を指摘します。

入力フォーマット:
入力ギブ2つの正の整数N(≤1000)学生の数と複数の選択肢の質問の数、それぞれ、最初の行及びM(≤100)。続いて、M行は、各行が順次、(5以下の正の整数)の質問のうちのオプションの数値が与えられる(正の整数以上2以上5)、オプションの正しい数(オプションは超えません正の整数)、すべての適切なオプション。小文字から各質問のためのオプションは、順次配置を始めることに注意してください。中でもスペースで区切られています。最後のN行は、各学生が答えにケースを与えている、すべての質問形式(選択したオプションオプション1 ......の数)、順番に指定されたタイトルへの答え。注:タイトル学生はケースが正当なものである答えを確認し、選択されたオプションの数は、オプションの実際の数よりも、存在しません。

出力フォーマットは:
入力、各スコアに対して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<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstring>
#include<sstream>
using namespace std;
//有的时候题目是一起做的,所以会有不需要的头文件

int main()
{
    int N, M;
    cin >> N >> M;

    //save score and key
    //0:score 1-5:abcde 6:num_true
    int score_key[M][8];
    int wrong_times[M] = { 0 };
    int score_stu[N] = { 0 };
    memset(score_key, 0, sizeof(score_key));
    for (int i = 0; i < M; i++)
    {
        cin >> score_key[i][0];
        int options, num_true;
        cin >> options >> num_true;
        score_key[i][6] = num_true;
        for (int j = 0; j < num_true; j++)
        {
            char t;
            cin >> t;
            score_key[i][t - 'a' + 1] = 1;
        }
    }
    string s;
    getline(cin, s);
    //student answers
    for (int i = 0; i < N; i++)//第i个学生
    {
        string student;
        getline(cin, student);
        for (int j = 0; j < M; j++)//第j道题
        {
            student.erase(0, student.find('(') + 1);
            if (student[0] - '0' == score_key[j][6])
            {
                for (int k = 0; k < score_key[j][6]; k++)
                {
                    student.erase(0, student.find(' ') + 1);
                    if (!score_key[j][student[0] - 'a' + 1])
                    {
                        wrong_times[j]++;
                        break;
                    }
                    if (k == score_key[j][6]-1)
                    {
                        score_stu[i] += score_key[j][0];
                    }
                }
            }
            else
            {
                wrong_times[j]++;
            }
        }
    }

    for (int i = 0; i < N; i++)
    {
        cout << score_stu[i] << endl;
    }

    int max_wrong = 0;
    for (int i = 0; i < M; i++)
    {
        if (wrong_times[i] > max_wrong)
            max_wrong = wrong_times[i];
    }

    if (max_wrong == 0)
    {
        cout << "Too simple";
        return 0;
    }

    cout << max_wrong;
    for (int i = 0; i < M; i++)
    {
        if (wrong_times[i] == max_wrong)
            cout << " " << i+1;
    }


    return 0;
}

公開された82元の記事 ウォンの賞賛1 ビュー1677

おすすめ

転載: blog.csdn.net/qq_34451909/article/details/104867689