当前位置:网站首页>PAT B1076

PAT B1076

2022-06-25 19:55:00 Madness makes freedom

1076 Wifi password (15 branch )

Here's a picture circulating on Weibo :“ Dear students , Since you sometimes need to use wifi, I'm afraid to delay my parents' study , Will now wifi The password is set to answer the following math question :A-1;B-2;C-3;D-4; Please answer by yourself , Change every two days . Thank You for Your Cooperation !!~”—— In order to promote students' learning, teachers also work hard …… This question requires you to write a program to translate the answers to a series of questions into wifi Password . Let's simply assume that each multiple-choice question has 4 An option , Yes and only 1 Right answer .

Input format :

The first line of input gives a positive integer N(≤ 100), And then N That's ok , Each line follows Number - answer The format gives the of a problem 4 An option ,T Indicates the correct option ,F Indicates the wrong option . The options are separated by spaces .

Output format :

Output in one line wifi password .

sample input :

8
A-T B-F C-F D-F
C-T B-F A-F D-F
A-F D-F C-F B-T
B-T A-F C-F D-F
B-F D-T A-F C-F
A-T C-F B-F D-F
D-T B-F C-F A-F
C-T A-F B-F D-F

sample output :

13224143

  Wrote two codes , The first is to enter a set of data , Output a value , But I don't think this way is very good , Although it's right , But after all, the project will be done later , It is not possible to enter a value , Just output a value . therefore , I used one string To store the results .

The first code :

#include <iostream>
#include <map>
#include <cstdio>
using namespace std;

int main()
{
    map<char,int> mp;
    for(int i=65,j=1;i<69;++i,++j)
    {
        mp.insert(make_pair(i,j));
    }
    int n;
    cin >> n;
    getchar();
    while(n--)
    {
        char c[4],answer[4];
        for(int i=0;i<4;i++)
        {
            scanf("%c-%c",&c[i],&answer[i]);
            getchar();
            if(answer[i]=='T')
                cout << mp[c[i]];
        }
    }
    return 0;
}

The second code :


#include <iostream>
#include <map>
#include <string>
#include <cstdio>
using namespace std;

int main()
{
    map<char,char> mp;
    for(int i=65,j=49;i<69;++i,++j)
    {
        mp.insert(make_pair(i,j));
    }
    int n;
    string str;
    cin >> n;
    getchar();
    while(n--)
    {
        char c[4],answer[4];
        for(int i=0;i<4;i++)
        {
            scanf("%c-%c",&c[i],&answer[i]);
            getchar();
            if(answer[i]=='T')
                str+=mp[c[i]];
        }
    }
    cout << str << endl;
    return 0;
}

原网站

版权声明
本文为[Madness makes freedom]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202190512262954.html