题解:P11395 喵喵喵幼儿园
A. 喵喵喵幼儿园 官方题解
本题考查的主要知识点:
- 【2】for, if 语句
- 【2】string
做法
本题分为两个步骤:正确读取字符串
定义 string a,Or,b;,然后依次读入三个字符串,则此时 b.pop_back(); 语句把
然后选择合适的字符串:
- 如果
a=="eat",那么检查b,如果也是eat,那么输出or,否则输出b这个字符串。 - 否则直接输出
a就可以了。(当然,你也可以再检查b,但是没什么必要)。
参考代码(C++):
#include<bits/stdc++.h>
using namespace std;
int T;
string a,Or,b;
int main(){
for(cin>>T;T;T--){
cin>>a>>Or>>b;
b.pop_back();
if(a=="eat"){
if(b=="eat")
cout<<"or\n";
else cout<<b<<"\n";
}
else
cout<<a<<"\n";
}
return 0;
}