P11395 喵喵喵幼儿园题解

题意

就是让你在两项中选一个不是eat的字符串。

前置知识

用scanf()输入是可以跳过一些你不想要的东西,在这道题中,我们可以用:

scanf("%s or %s", &a, &b);

来跳过中间的or。

有聪明的小伙伴就要问了,为什么不能把问号给跳过呢???

因为程序先输入完 $b$ 后才去看第二个 $\%d$ 后面的问号,所以已经跳过不了问号。

思路

很简单,没什么好说的,注意scanf()不能输入string类型,要用char,输入后用strcmp()来判断是不是eat。

Code

#include <iostream>
#include <cstring>
using namespace std;
int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        char a[105], b[105];
        scanf("%s or %s", &a, &b);
        //cout << a << b;
        if(strcmp(a, "eat") == 0 && strcmp(b, "eat?") == 0)
        {
            cout << "or\n";
        }
        else if(strcmp(a, "eat") == 0)
        {
            for(int j = 0; j <= 105; j++)
            {
                if(b[j] == '?')
                {
                    break;
                }
                cout << b[j];
            }
            cout << "\n";
        }
        else if(strcmp(b, "eat?") == 0)
        {
            cout << a << "\n";
        }
        else
        {
            cout << a << "\n";
        }
    }
    return 0;
}