求助这个解法有什么漏洞
  • 板块P1106 删数问题
  • 楼主BearBig
  • 当前回复3
  • 已保存回复3
  • 发布时间2022/11/13 19:58
  • 上次更新2023/10/27 03:03:49
查看原帖
求助这个解法有什么漏洞
668599
BearBig楼主2022/11/13 19:58

rt,84,WA * 1

#include<bits/stdc++.h>
using namespace std;
stack<char>num;
int main()
{
	string st;int k;cin>>st>>k;
	for(int i=0;i<st.length();++i)
	{
		if(!k or num.empty())
		{
			num.push(st[i]);
			continue;
		}
		if(st[i]<num.top())
			while(st[i]<num.top())
			{
				--k;num.pop();
				if(num.empty())break;
			}
		if(num.empty())
			num.push(st[i]);
		else if(st[i]>=num.top())
			num.push(st[i]);
	}
	while(k-- and num.size())num.pop();
	stack<char>st2;while(num.size())
	{st2.push(num.top());num.pop();}
	while(st2.size())
	{
		if(st2.top()^48)break;
		else st2.pop();
	}if(st2.empty())puts("0");
	while(st2.size())
	{cout<<st2.top();st2.pop();}
}
2022/11/13 19:58
加载中...