#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
/*
Below are the permutations of string ABC.
ABC ACB BAC BCA CBA CAB
ABSG
ABGS ABSG AGBS AGSB ASBG ASGB
BAGS BASG BGAS BGSA BSAG BSGA
GABS GASB GBAS GBSA GSAB GSBA
SABG SAGB SBAG SBGA SGAB SGBA
*/
char *input;
int count;
void getInput(){
input = calloc(32, sizeof(char));
scanf("%s", input);
count = strlen(input);
}
void perumtations2(int n){
if(n == count - 1){
return ;
}
char m = input[n];
input[n] = input[n + 1];
input[n + 1] = m;
printf("%s ", input);
perumtations2(n + 1);
}
int calculator = 0;
void permutations(int n){
if(n == count){
calculator++;
printf("%s ", input);
return ;
}
for(int i = n; i < count; i++){
char m = input[i];
input[i] = input[n];
input[n] = m;
permutations(n + 1);
m = input[i];
input[i] = input[n];
input[n] = m;
}
return false;
}
int main(){
getInput();
printf("The solution is:\n");
permutations(0);
printf("\n");
printf("calculator:%d\n",calculator);
free(input);
return 0;
}