Find the maximum number (c) time limit: +Ms | Memory Limit:65535KB Difficulty:2
-
-
Describe
-
Given an integer n, you can move a number on 2 adjacent digits at a time, moving up to K times, and getting a new integer.
What is the maximum value for this new integer.
-
-
Input
-
-
Multiple sets of test data.
One row for each set of test data, with two numbers n and K per line (1?≤? n≤?10^18; 0?≤? K?≤?100).
-
-
Output
-
The
-
output of each set of test data takes one row, and the output moves to get the maximum value of the new integer.
-
-
Sample input
-
-
1990 1100 09090000078001234 6
-
-
Sample output
-
-
91901009907000008001234
-
-
-
-
Ideas:
-
-
At first I thought that I met a large number ahead of the move one, the result WA, and then think of moving steps in the interval moved, very happy to make the submission, the result is WA again. The original self-made careless fault, originally was moved, but suddenly forgot, the result is directly subscript the element.
-
-
My Code:
-
-
-
-
#include <iostream> #include <algorithm>using namespace Std;int main () {int K,i,j,t;char a[25],b;while (CIN & Gt;>a >> k) {for (i=0;a[i]!= ' &&k>0;++i)//Array length {b=a[i];for (j=i+1;j<=i+k&&a[j]!= ' \ 0 '; ++j)//k the largest number in the interval {if (b-' 0 ' <a[j]-' 0 ') {b=a[j];t=j;}} if (B!=a[i]) {k-=t-i;for (j=t;j>i;--j) {swap (a[j],a[j-1]);}}} cout << a << Endl;} return 0;}
Find maximum number (c)