码迷,mamicode.com
首页 > 其他好文 > 详细

tne number which is made of the number of remaining is smallest

时间:2017-09-21 16:39:32      阅读:97      评论:0      收藏:0      [点我收藏+]

标签:find   ade   int   ber   last   point   out   return   elements   

#include <iostream>
#include <string>
using namespace std;


void deleteDigite(int k, string str)
{
int len = str.length();
for(int i=0; i<k; i++) //there are k elements that need to be deleted
{

for(int j=0; j<len-1; j++) //the most times of cycles are len-1,if the second element is smaller than the previous,delete the first one, it is the great point
{
if(str[j]>str[j+1]) //if we meet the great point, we erase it
{
str.erase(j, 1);
len--;
break;
}
if(j==len-1) //if we arrive the end of string, but we did‘t find the element smaller than the previous one, the last one is a great point. erase it;
{
str.erase(j, 1);
}
}

}
cout << str;
}
int main()
{
string a = "1253879";
deleteDigite(2, a);
return 0;
}

tne number which is made of the number of remaining is smallest

标签:find   ade   int   ber   last   point   out   return   elements   

原文地址:http://www.cnblogs.com/1915884031A-qqcom/p/7569160.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!