50

Description

给定一个n位正整数a,删掉其中任意k(k<=n)个位,剩下的按原顺序形成一个新的正整数。找出剩下的数字最小的删数方案。编程任务:给定正整数a,删掉k位数字,计算剩下的最小数字。

Input

程序输入包括两个数字:正整数a>0,删掉的位数k(0<k<=n),其中n为a的位数。

Output

最小的剩下的数。

Sample Input

178543 4

Sample Output

1


#include <iostream>
#include <algorithm>
#include <string.h>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
using  namespace std;
int main()
{
  ios::sync_with_stdio(false);
  int k,i,flag;
  string n;
  while(cin>>n>>k)
  {
    vector <char> s(n.begin(),n.end());
    while(k--)
    {
      vector <char>::iterator j=s.begin();
      i=0;
      while(i!=s.size()-1)
      {
        flag=1;
        if(s[i]>s[i+1])
        {s.erase(j);flag=0;break;}
        i++;j++;
      }
      if(flag)
      s.erase(j);
    }
    for(i=0;i<s.size();i++)
      if(s[i]!='0')break;
    while(i!=s.size())
      cout<<s[i++];
    cout<<endl;
  }
  return 0;
}
 
原文地址:https://www.cnblogs.com/acm-icpcer/p/6869494.html