Xidianoj 1123 k=1 Problem of Orz Pandas

Source: Internet
Author: User

Title Description

one panda named Orz is playing a interesting game, he gets a big integer Num and an integer k num k times. So what's the biggest number after in most K times operations?

However, a VIP (Very Important Panda) of ACM/OPPC (Orz Panda programming Contest) Comittee thought this problem is to o Hard for Orz Pandas. So he simplified the problem with constraint k=1. Your task is to solve the simplified problem.

Input

Multiple cases. For each case:
The first line was an integer num. 0≤num≤10, and it was guaranteed that Num is a legal integer and Doesn ' t contain any leading zero

Output

For the all test case, print the biggest number after the on most 1 times operation in a line.

--Body string read number, greedy to find the number of possible exchange
#include <iostream>#include<cstring>#include<cstdio>#include<algorithm>using namespacestd;Charnum[1001];intFindmax (Char*num) {    intLen =strlen (num); intmax =-1, Maxi; inti;  for(i=0; i<len;i++){        if(Num[i]-'0'>=max) {Max= Num[i]-'0'; Maxi=i; }    }    returnMaxi;}intMain () { while(SCANF ("%s", num)! =EOF) {        Char* begin =num; intLen =strlen (num); intTotal =0; BOOLover =false;  while(!Over ) {            intMaxi = Findmax (&num[total]) +Total ; intnow =Total ;  while(Num[now] = = Num[maxi] && now < maxi) now++; if(now = =Maxi) { Total= maxi+1; if(Num[total] = =' /') Break; Continue; }            Else {                Chartemp =Num[now]; Num[now]=Num[maxi]; Num[maxi]=temp;  Break; }} printf ("%s\n", begin); }    return 0;}

Xidianoj 1123 k=1 Problem of Orz Pandas

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.