10098-generating Fast
Time limit:3.000 seconds
http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1039
Generating permutation has always been a important problem in computer. In this problem your have to generate the permutation of an a given string in ascending order. Remember that your algorithm must to be efficient.
Input
The ' I ' input contains an integer n, which indicates how many strings to follow. The next n lines contain n strings. Strings'll only contain alpha numerals and never contain any spaces. The maximum length of the string is 10.
Output
For each input string, print all, the permutations possible in ascending. Not that the strings should is treated, as case sensitive strings and no permutation should is repeated. A blank line should follow each output set.
Sample Input
3
Ab
Abc
Bca
Sample Output
Ab
Ba
Abc
Acb
Bac
Bca
Cab
Cba
Abc
Acb
Bac
Bca
Cab
Cba
STL algorithm is done.
Complete code:
01./*0.042s*/
.
#include <cstdio>
#include <cstring>
#include <algorithm>
06.using namespace Std;
08.char str[15];
10.int Main (void)
11.{ int T, Len; scanf ("%d\n", &t);
While (t--)
. { gets (str); len = strlen (str); sort (str, str + len);
. Puts (str);
While (next_permutation (str, str + len);///This method does not duplicate output
. Putchar (' \ n ');
. return 0;
25.}
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/