求调
查看原帖
求调
1251525
wisdom2010楼主2025/1/21 14:54
#include<bits/stdc++.h>
using namespace std;
string n;
int k;
const int maxn = 250 + 10;
int a[maxn];
int main()
{
	ios :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> k;
	int len = n.size();
	int cnt = 0;
	for(int i = 0; i < len + 10; i++)
		a[i] = 1;
	for(int i = 0; i < len - 2; i++)
	{
		if(n[i] > n[i + 1])
		{
			for(int j = i; j >= 0; j--)
			{
				if(a[j] == 0)
					continue;
				if(cnt == k)
					break;
				if(n[j] <= n[i + 1])
					break;
				a[j] = 0;
				cnt++;
			}
		}
		
	}
	if(cnt < k)
	{
		for(int i = len - 1; i >= 0; i--)
		{
			if(a[i] == 0)
				continue;
			a[i] = 0;
			cnt++;
			if(cnt == k)
				break;
		}
	}
	for(int i = 0; i < len; i++)
	{
		if(a[i] == 0)
			continue;
		cout << n[i];
	}
	return 0;
}
2025/1/21 14:54
加载中...