View Code of Problem 609

#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<cctype>
using namespace std;
/*解题思路:在这个动态过程中,删掉如果前一个数字大于后一个数字,删掉前面的*/
/*例如:18573,删除3次,第一次删除8,变为1573,第二次删除7,变为153,第三次删除5,变为13*/ 
int main()
{
	string str;
	int i,n;
	while( cin>>str ){
		cin>>n;
		while( n-- ){
			for(i=0;i<str.size();i++){
				if( str[i]>str[i+1] ||i == str.size()-1 ){
					str.erase(i,1);break;
				}
			} 
		}
		//删除前导0;
		while( str[0] == '0' ){
			str.erase(0,1);
		} 
		//判断是不是全部都是0,那就是全部都删除完了,需要判空
		if( str.empty() ){
			cout<<0<<endl;
		} else cout<<str<<endl;
	} 
}

Double click to view unformatted code.


Back to problem 609