rt,遇到了玄学问题,求大佬指教
WA+RE+AC 代码:
#include<bits/stdc++.h>
using namespace std;
stack<char>s;
string st;int k;
int main()
{
cin>>st>>k;
for(int i=0;i<st.length();++i)
{
if(!k)
{
s.push(st[i]);
continue;
}
if(s.empty())s.push(st[i]);
else
{
if(s.top()>st[i])
{
s.pop();--k;
}
else s.push(st[i]);
}
}
while(k>0){--k;s.pop();}
string num("");
while(s.size())
{
num=s.top()+num;
s.pop();continue;
}
string res("");
for(int i=0;i<num.length();++i)
if(!res.length() and num[i]=='0')
continue;else res+=num[i];
if(res.empty())cout<<"0";
else cout<<res;
}
AC 代码:
#include<bits/stdc++.h>
using namespace std;
stack<char>s;
string st;int k;
int main()
{
cin>>st>>k;
for(int i=0;i<st.length();)
{
if(!k)
{
s.push(st[i++]);
continue;
}
if(s.empty())s.push(st[i++]);
else
{
if(s.top()>st[i])
{
s.pop();--k;
}
else s.push(st[i++]);
}
}
while(k>0){--k;s.pop();}
string num("");
while(s.size())
{
num=s.top()+num;
s.pop();continue;
}
string res("");
for(int i=0;i<num.length();)
if(!res.length() and num[i]=='0')
{++i;continue;}
else res+=num[i++];
if(res.empty())cout<<"0";
else cout<<res;
}