4495. Print permutations

来源:互联网 发布:windows loader v2.4 编辑:程序博客网 时间:2024/06/05 20:49

4495. Print permutations

Description

A permutation is a possible ordering of a set. For example, the permutations of a set {A,B,C} include ABC, ACB, BAC, BCA, CAB, CBA.
The number of permutations of a set of N elements is N!. The example set above has 3 elements and it has a number of 3!=6 permutations.
Given a line with N different upper letters, please print N! lines containing all different permutations of the N letters. These N! lines are printed in dictionary order.

Input

A line with N (1<=N<=8) different upper letters given in dictionary order.

Output

N! lines containing all different permutations of the N letters. These N! lines are printed in dictionary order.

Sample Input

ABCD

Sample Output

ABCDABDCACBDACDBADBCADCBBACDBADCBCADBCDABDACBDCACABDCADBCBADCBDACDABCDBADABCDACBDBACDBCADCABDCBA

#include <iostream>#include <string>#include <algorithm>using namespace std;int main(){    string a;    getline(cin,a);    int len=a.length();    int b[8];    for(int i=0;i<len;i++)            b[i]=a[i]-'0';    do{for(int i = 0; i < len; i++){cout << char(b[i]+'0'); }cout <<endl;} while (next_permutation(b, b + len));return 0;}        


原创粉丝点击