Find maximum number (c)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.