题目链接:删除字符
tm,我是菜菲,这个题竟然看了这么久。另外,没好的思路的时候,去csdn上找博客,竟然没有一篇我觉得不错的!最后,只想骂自己,骂其他的博客。希望对你有用,本小菲羊的第二篇给爱学习的people看的博客~
核心代码:
void solve()
{
cin>>s>>n;
stack<char>st;
for(int i=0;i<s.size();i++)
{
while(n>0&&st.empty()==0&&st.top()>s[i])//n>0
{
st.pop();n--;
}
st.push(s[i]);
}
while(n>0)//如果没有删完,从后面开始删,这题数据不够,没有这个也过了
{
st.pop();n--;
}
string x;
while(st.empty()==0)
{
x+=st.top();st.pop();
}
reverse(x.begin(),x.end());
cout<<x;
}
}