#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 100010;
string s, res;
int main()
{
int k;
cin >> s >> k;
//消除逆序对
res = "0";
for (int i = 0; i < (int)s.size(); i++) {
while (s[i] < res.back() && k)
{
res.pop_back();
k--;
}
res += s[i];
}
while (k--) res.pop_back();
//逆序对都排除完了,k若不为0,从大到小开始删除
int i = 0;
while (i < res.size() && res[i] == '0')
i++;
//判断前导零个数
if (i == res.size()) cout << "0" << endl;
else cout << res.substr(i) << endl;
}
Acwing 1453
最新推荐文章于 2023-03-31 23:33:24 发布