B. Pasha Maximizes

B. Pasha Maximizes
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.

Help Pasha count the maximum number he can get if he has the time to make at most k swaps.

Input

The single line contains two integers a and k (1 ≤ a ≤ 1018; 0 ≤ k ≤ 100).

Output

Print the maximum number that Pasha can get if he makes at most k swaps.

Sample test(s)
input
1990 1
output
9190
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>


using namespace std;


int main()
{
   int num,n;
   char str[207];
   scanf("%s %d",str, &n);


   int pos = 0;
   int len = strlen(str);
   //cout<<n<<endl;
   int i, j, k;
   for(  i = 0; i < len; i++)
   {
        int maxn = str[i]-'0';
       //cout<<str<<endl;
        if( n == 0)
         break;
        for(  j = i+1 ; j  <= i+n && j < len; j++)
        {
          // cout<<maxn<<endl;
           if(str[j] - '0' > maxn)
            {
                maxn = str[j] - '0';
                pos = j;
            }
        }
      if( maxn == str[i]-'0' )
        continue;


       for(  k = pos; k > i; k--)
       {
           //cout<<"k"<<k<<endl;
           swap(str[k],str[k-1]);
       }


      n = n - pos + i;
     // cout<<i<<"pos"<<pos<<endl;
   }
   cout<<str<<endl;
}

你可能感兴趣的:(B. Pasha Maximizes)