/删除子串,可能从中间删除,类似 括号匹配 的题目,使用栈来写
#include <iostream>
#include <algorithm>
#include <stack>
#define ll long long
using namespace std;
int main()
{
int n;
string s;
cin>>n>>s;
stack<char> st;
bool ans=true;
for(int i=0;i<n;i++)
{
if(s[i]=='n')
st.push('n');
else if(s[i]=='i')
st.push('i');
else if(s[i]=='u')
{
if(st.empty())
{
ans=0;
break;
}
char tmp1=st.top();
st.pop();
if(st.empty())
{
ans=0;
break;
}
char tmp2=st.top();
if(tmp1=='i'&&tmp2=='n')
{
st.pop();
}
else
{
ans=false;
break;
}
}
else if(s[i]=='m')
{
st.push('m');
}
else if(s[i]=='o')
{
if(st.top()=='m')
st.pop();
else
{
ans=false;
break;
}
}
}
if(ans)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
return 0;
}