竞赛
考级
这道题比较简单,只需要先判断是不是meow四个字母都有,再判断首尾是不是分别为m和w,然后进行一个for循环,从s[1]到s[len-1], 如果s[i]是w,那么他前面的数只能是m, 如果是e,前面只能是e和m, 如果是o,前面只能是e和o, 如果是w,前面只能是w和o。 如果不满足,直接输出NO然后return 0. code: 代码虽长,但是简单。 别忘了加入我的团队: 中国
核心内容是字符串模拟,没有复杂的逻辑,只要逐步判断即可,注意细节。
#include<bits/stdc++.h> using namespace std;string s;bool flag=1;int ans=1,top=1;int main(){stdcin>>s;s=' '+s;if(ans1){bool f=false;for(int j=top;j<s.size()-1&&(s[j]'m'||s[j]'M');j++){top++;f=true;}if(!f)flag=false;ans=2;}if(ans2){bool f=false;for(int j=top;j<=s.size()-1&&(s[j]'e'||s[j]'E');j++){top++;f=true;}if(!f)flag=false;ans=3;}if(ans3){bool f=false;for(int j=top;j<=s.size()-1&&(s[j]'O'||s[j]'o');j++){top++;f=true;}if(!f)flag=false;ans=4;}if(ans4){bool f=false;for(int j=top;j<=s.size()-1&&(s[j]'w'||s[j]'W');j++){top++;f=true;}if(!f)flag=false;ans=4;}stdcout<<(flag&&top==s.size()?"YES":"NO");return 0;}
提交答案之后,这里将显示提交结果~