卡第五个点,不知道咋改了,大神帮忙调一下
#include<bits/stdc++.h>
using namespace std;
const int N=500;
typedef pair<int, int> PII;
int a[N];
bool mk[N];
string s;
stack<int> b;
int n, k;
void outputs()
{
int flag = 0;
queue <int> ans;
for (int i = 0; i < n; i ++ )
{
if (mk[i])
{
if(a[i] || flag)
{
ans.push(a[i]);
flag = 1;
}
}
}
if(ans.empty()) cout << 0;
else
{
while (ans.size())
{
cout << ans.front();
ans.pop();
}
}
}
void solve()
{
cin >> s >> k;
n = s.length();
for (int i = 0; i < n; i ++ )
{
a[i] = s[i] - '0';
}
int cnt = 0;
while (1)
{
for (int i = 0; i < n; i ++ )
if (!mk[i])
{
while (b.size())
{
int t = b.top();
if (a[t] > a[i])
b.pop();
else
break;
}
if (b.empty() || cnt < n - k)
{
b.push(i);
}
}
while (b.size() > n - k) b.pop();
while (b.size())
{
int t = b.top();
b.pop();
mk[t] = true;
cnt ++;
if(cnt == n - k)
{
outputs();
return;
}
}
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while( t -- )
{
solve();
}
}