UVa 10098 generating Fast: Full array generation

Source: Internet
Author: User
Tags time limit

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/

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.