PAT Class B 1052 Be cute (problem-solving ideas + AC code)

topic:

Moemoe emoticons are usually composed of three main parts: "hand", "eye" and "mouth". For simplicity, we assume that an emoji is output in the following format:

[左手]([左眼][口][右眼])[右手]

Now give a set of optional symbols, please output emoticons according to the user's requirements.

Input format:

The input first gives the optional symbol sets of hands, eyes, and mouths in the first three lines. Each symbol is enclosed in a pair of square brackets []. The title guarantees that each set has at least one symbol and no more than 10 symbols; each symbol contains 1 to 4 non-null characters.

The next line gives a positive integer K, which is the number requested by the user. Followed by K lines, each line gives a user's symbol selection, the order is left hand, left eye, mouth, right eye, right hand - only the serial number of the symbol in the corresponding set (starting from 1) is given here, and the numbers are separated by spaces separated.

Output format:

For each user request, output the generated emoji on one line. If the serial number selected by the user does not exist, it is output Are you kidding me? @\/@.

Input sample:

[╮][╭][o][~\][/~]  [<][>]
 [╯][╰][^][-][=][>][<][@][⊙]
[Д][▽][_][ε][^]  ...
4
1 1 2 2 2
6 8 1 5 5
3 3 4 3 3
2 10 3 9 3

Sample output:

╮(╯▽╰)╭
<(@Д=)/~
o(^ε^)o
Are you kidding me? @\/@

Code length limit 16 KB
time limit 400 ms
memory limit 64 MB

 

problem solving ideas

  1. Given the three optional character sets of "hand", "eye", and "mouth", we need to extract their valid characters in order and put them into a vector container (the The element type is string type.
  2. Then the serial number -1 of the input "hand", "eye" and "mouth" corresponds to the subscript in the vector, and it can be output; but if the serial number selected by the user does not exist, then output, because it is Are you kidding me? @\/@a \transfer Escape characters cannot be output directly, so you need to \escape with another escape character to \\output backslashes.

 

AC code

#include <bits/stdc++.h>
using namespace std;

int main()
{
    
    
    vector<string> v[3];
    for (int i = 0; i < 3; i++)
    {
    
    
        string tmp;
        //由于一行中可能出现空格,所以不能用cin进行输入,需要用getline进行输入一行
        getline(cin, tmp);		
        int find1 = 0;
        int find2 = 0;
        while (1)
        {
    
    
            find1 = tmp.find('[', find1);
            find2 = tmp.find(']', find2);
            if (find1 == -1 && find2 == -1)
            {
    
    
                break;
            }
            v[i].push_back(tmp.substr(find1+1, find2 - find1 -1));
            find1++;
            find2++;
        }
    }
    int n = 0;
    cin >> n;
    while (n--)
    {
    
    
        int a1, a2, a3, a4, a5 = 0;
        cin >> a1 >> a2 >> a3 >> a4 >> a5;
        a1 -= 1; a2 -= 1; a3 -= 1; a4 -= 1; a5 -= 1;
        if (a1 >= v[0].size() || a2 >= v[1].size()
           || a3 >= v[2].size() || a4 >= v[1].size()
           || a5 >= v[0].size())
        {
    
    
            cout << "Are you kidding me? @\\/@" << endl;
        }
        else
        {
    
    
            cout << v[0][a1] << "(" << v[1][a2] << v[2][a3] 
                << v[1][a4] << ")" << v[0][a5] << endl;
        }
    }
    return 0;
}

Guess you like

Origin blog.csdn.net/m0_70103775/article/details/131294083