hdu 3183 A Magic Lamp

11 篇文章 0 订阅

http://acm.hdu.edu.cn/showproblem.php?pid=3183

题意:从一个数里删除n个数字,使其最小

分析:只需判断第i个数是否大于第i+1个数,实则删掉,否则继续寻找;注意0的存在,只要第二位数是0,直接删除第一个数即可,因为数的位数减少了

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;

int main()
{
	string str,str1,str2;
	int i,n,len;
	while(cin>>str>>n)
	{
		while(n--&&str.size()>0)
		{
			len=str.size();
			i=1;
			if(str[i]=='0')
			{
				while(str[i]=='0')
					i++;
				str.assign(str,i,len);
			}
			else if(str[0]<=str[i])
			{
				while(str[i-1]<=str[i])
					i++;
				str1.assign(str,0,i-1);
				str2.assign(str,i,len);				
				str=str1+str2;
			}
			else
			{
				str.assign(str,i,len);
			}
		}
		if(str.size()==0)
			cout<<"0"<<endl;
		else
		cout<<str<<endl;
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值