4.
#include <stdio.h>
#include <string.h>
void swap(char x, char y)
{
char temp;
temp = x;
x = y;
y = temp;
}
void permute(char a[], int l, int r)
{
int i;
if (l == r)
printf("%s\n", a);
else
{
for (i = l; i < r; i++)
{
permute(a, l+1, r);
swap(a[l], a[i]);
swap(a[l], a[i]);
}
}
}
int main()
{
char str[100];
int t,n;
scanf(“%d”,&t);
while(t--) {
scanf(“%d”,&n);
scanf("%s",&str);
permute(str, 0, n-1);
}
return 0;
}
Input Format
Number of test case
an integer - length of the string
string of above length
Output Format
Strings of above length each in new line
Sample Input
1
3
abc
Sample Output
abc
acb
bac
bca
cba
cab
Constraints :
1<= testcases <=25
0 < length of the string < 100