Sample Input
2
9128456 2
1444 3
Sample Output
12456
1
思路:k次遍历字符串,每次遍历时,只有较高位上数字比较低位数字大时,删除较高位,得到的数字会更小。如果是递增序列,则删除最后一位数字。
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t,k;
string s;
cin>>t;
while(t--)
{
cin>>s>>k;
while(k--)
{
bool f=0;
for(int i=0;i<s.size();i++)
{
if(s[i]>s[i+1]) {s.erase(i,1),f=1;break;}
}
if(!f) s.erase(s.size()-1,1);
}
cout<<s<<endl;
}
return 0;
}