Tip : You need to learn STL ( <algrithm > ) to solve this problem . Otherwise it will be difficult to solve manually . See down .
Code :
#include<bits/stdc++.h>
using namespace std;
int main()
{
char a[11];
int n;
scanf("%d",&n);
while(n--)
{
scanf("%s",a);
int len = strlen(a);
sort(a,a+len);
do
{
printf("%s\n",a);
}while(next_permutation(a,a+len)); //next_permutation(); is an STL.
printf("\n");
}
return 0;
}
how this stl works pls explain
ReplyDeletehttp://www.cplusplus.com/reference/algorithm/next_permutation/
DeleteClick on this link . You will have details about it . In general, Its an STL that Generate Next Permutations of the Current one .