社区讨论
求助这个解法有什么漏洞
P1106删数问题参与者 3已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @lo7jyz7v
- 此快照首次捕获于
- 2023/10/27 03:03 2 年前
- 此快照最后确认于
- 2023/10/27 03:03 2 年前
rt,84,WA * 1
CPP#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();}
}
回复
共 3 条回复,欢迎继续交流。
正在加载回复...