The Next permutation
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 850 Accepted Submission (s): 597
Problem descriptionfor This problem, you'll write a program that takes a (possibly long) string of decimal digits, and O Utputs the permutation of those decimal digits that have the next larger value (as a decimal number)
than the input number. For example:
123
279134399742-279134423799
It is possible this no permutation of the input digits has a larger value. For example, 987.
Inputthe first line of input contains a single integer P, (1≤p≤1000), which are the number of data sets that follow. Each of the data set is a contains the data set number, followed by a space, and followed by up to the decimal digits Which is the input value.
Outputfor Each data set there are one line of output. If there is no larger permutation of the input digits, the output should being the data set number followed by a single space , followed by the string
biggest. Ifthere is a solution, the output should being the data set number, a single space and the next larger
Permutation of the input digits.
Sample Input31 1232 2791343997423 987
Sample OUTPUT1 1322 2791344237993 biggest
Source2009 Greater New York Regional STL Dafa
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath > #include <cstdlib> #include <algorithm> #include <queue> #include <vector> #include < stack> #include <set> #include <map>using namespace Std;char s[81];int main () { int tt,x; scanf ("%d", &tt); while (tt--) { scanf ("%d%s", &x,s); int Len=strlen (s); if (Next_permutation (S,s+len)) printf ("%d%s\n", x,s); else printf ("%d biggest\n", x); } return 0;}
(STL Dafa) HDU 3283