summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorSanto Cariotti <sancn@live.com>2017-11-01 16:41:36 +0100
committerSanto Cariotti <sancn@live.com>2017-11-01 16:41:36 +0100
commite8f63b8e3ac794007d7a8d6d75e9f65917f760e0 (patch)
tree45950e82c0c4cabda7a18947c9bd04cb88462e4d /cpp
parentcb75a519ad8c6b4fce629b9cf5ba2a11131eb041 (diff)
anagrams in c
Diffstat (limited to 'cpp')
-rw-r--r--cpp/anagrams.c25
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;
+}