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