bestlv


私信TA

用户名:peikailv

访问量:942

签 名:

等  级
排  名 2872
经  验 2037
参赛次数 0
文章发表 11
年  龄 0
在职情况 学生
学  校 福州大学
专  业 计算机类

  自我简介:

解题思路:
贪心算法,局部最优解:先删掉递增区间的末尾,若删的数不够,再从末尾开始删(此时从左往右已经是递增序列),特别注意在最后要处理开头是0的情况。
注意事项:

参考代码:

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
int n,m;
string t;
int main()
{
    cin>>t;
    n=t.size();
	cin>>m;
	int temp=m;

	while(m>0)
	{
		int i=0;
		for(;i<n;i++)
		{
			if(t[i]>t[i+1])
			{
		    t.erase(i,1);
		    m--;
			break;
			}
		}
		if(i==n-1) break;
	}
//	cout<<n-m<<endl;
    while(m--) t.erase(n-1,1);
    int pos=0;
    while(t[pos]=='0'&&pos<t.size()-1) pos++;
	for(int i=pos;i<t.size();i++)
	{
		cout<<t[i];
	}
	return 0;
}


 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区