diff options
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/anagrams.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/cpp/anagrams.c b/cpp/anagrams.c new file mode 100644 index 0000000..018e00e --- /dev/null +++ b/cpp/anagrams.c @@ -0,0 +1,25 @@ +#include <stdio.h> +#include <string.h> +void swap(char* a, char* b) { + char t = *a; + *a = *b; + *b = t; +} + +void anagrams(char* str, int l, int r) { + if(l == r) + printf("%s\n", str); + else + for(int i = l; i < r; i++) { + swap(&str[l], &str[i]); + anagrams(str, l+1, r); + //swap(&str[l], &str[i]); + } +} + +int main() { + char str[30]; + scanf("%s", str); + anagrams(str, 0, strlen(str)); + return 0; +} |