diff options
author | Santo Cariotti <sancn@live.com> | 2017-11-01 16:41:36 +0100 |
---|---|---|
committer | Santo Cariotti <sancn@live.com> | 2017-11-01 16:41:36 +0100 |
commit | e8f63b8e3ac794007d7a8d6d75e9f65917f760e0 (patch) | |
tree | 45950e82c0c4cabda7a18947c9bd04cb88462e4d /cpp | |
parent | cb75a519ad8c6b4fce629b9cf5ba2a11131eb041 (diff) |
anagrams in c
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; +} |