PATB1076 wifi password string processing

Title Description

Here is circulating on Weibo photo: "Dear students, given that we sometimes need to use wifi, afraid to delay the pro learning, now wifi password is set to answer the following math problem: A-1; B- 2; C-3; D-4;. ask someone to answer their own, a change every two days - thank you !! "- teachers to promote student learning is the fight ...... this question requires you to write a series of procedures to the answer to the title translated into the wifi password is given in accordance with the correspondence between the papers. Here simply assume that each multiple-choice questions have four options and only one correct answer.

wifi.jpg

Input formats:

The first input line is given a positive integer N (≤ 100), followed by N rows, each row in accordance with the 编号-答案given four options a question format, Tshowing the correct option, Fan error option. Separated by spaces option.

Output formats:

Output wifi passwords in a row.

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

analysis

Looking characters, first two characters T is the correct letter, can be converted to digital. My idea was more complicated. Liu can refer to God, her approach is less than 10 lines.

Code

#include <iostream>
#include <string>
int main(){
    int n, tmp;
    std::string str, res;
    std::cin >> n;
    std::getchar();
    for (int i = 0; i < n; i++) {
        getline(std::cin, str);
        tmp = str.find('T');
        tmp -= 2;
        if (str[tmp] == 'A') res += '1';
        if (str[tmp] == 'B') res += '2';
        if (str[tmp] == 'C') res += '3';
        if (str[tmp] == 'D') res += '4';
    }
    std::cout << res;
    return 0;
}

Guess you like

Origin blog.csdn.net/qq_40677350/article/details/90729107