牛客周赛 Round 140 B 小红的牛魔
2026/4/22 19:47:54 网站建设 项目流程

/删除子串,可能从中间删除,类似 括号匹配 的题目,使用栈来写

#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;
}

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询