From ee9e359044c2d00e2b24027c57d9ee2140f92a87 Mon Sep 17 00:00:00 2001 From: thimira nirmal Date: Wed, 20 Oct 2021 22:24:54 +0530 Subject: [PATCH 1/3] Anagram CPP --- String Algorithms/Anagram/Anagram.cpp | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 String Algorithms/Anagram/Anagram.cpp diff --git a/String Algorithms/Anagram/Anagram.cpp b/String Algorithms/Anagram/Anagram.cpp new file mode 100644 index 0000000..94f500f --- /dev/null +++ b/String Algorithms/Anagram/Anagram.cpp @@ -0,0 +1,29 @@ +#include +#include + +using namespace std; + +bool Anagram (string str1, string str2){ + int n1 = str1.length(); + int n2 = str2.length(); + + if (n1 != n2) return false; + + sort(str1.begin(), str1.end()); + sort(str2.begin(), str2.end()); + + for (int i = 0; i < n1; i++) + if (str1[i] != str2[i]) + return false; + return true; +} + +int main() { + string str1 = "listen"; + string str2 = "silent"; + + // Note that each letter need to be in same case. Otherwise, use toUpper Function before adding to function. + + cout << (Anagram(str1, str2) ? "Anagram" : "Not Anagram"); + +} \ No newline at end of file From 1d973e019535e2c6f508a0131f1681dabcb084a9 Mon Sep 17 00:00:00 2001 From: thimira nirmal Date: Wed, 20 Oct 2021 22:28:28 +0530 Subject: [PATCH 2/3] Anagram CPP --- String Algorithms/Anagram/Anagram.cpp | 29 --------------------------- 1 file changed, 29 deletions(-) delete mode 100644 String Algorithms/Anagram/Anagram.cpp diff --git a/String Algorithms/Anagram/Anagram.cpp b/String Algorithms/Anagram/Anagram.cpp deleted file mode 100644 index 94f500f..0000000 --- a/String Algorithms/Anagram/Anagram.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include - -using namespace std; - -bool Anagram (string str1, string str2){ - int n1 = str1.length(); - int n2 = str2.length(); - - if (n1 != n2) return false; - - sort(str1.begin(), str1.end()); - sort(str2.begin(), str2.end()); - - for (int i = 0; i < n1; i++) - if (str1[i] != str2[i]) - return false; - return true; -} - -int main() { - string str1 = "listen"; - string str2 = "silent"; - - // Note that each letter need to be in same case. Otherwise, use toUpper Function before adding to function. - - cout << (Anagram(str1, str2) ? "Anagram" : "Not Anagram"); - -} \ No newline at end of file From d286aeaa17e9b10f8bd6eb86d3038ff1a0f547ed Mon Sep 17 00:00:00 2001 From: thimira nirmal Date: Wed, 20 Oct 2021 22:29:22 +0530 Subject: [PATCH 3/3] Anagram CPP --- String Algorithms/Anagram/Anagram.cpp | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 String Algorithms/Anagram/Anagram.cpp diff --git a/String Algorithms/Anagram/Anagram.cpp b/String Algorithms/Anagram/Anagram.cpp new file mode 100644 index 0000000..94f500f --- /dev/null +++ b/String Algorithms/Anagram/Anagram.cpp @@ -0,0 +1,29 @@ +#include +#include + +using namespace std; + +bool Anagram (string str1, string str2){ + int n1 = str1.length(); + int n2 = str2.length(); + + if (n1 != n2) return false; + + sort(str1.begin(), str1.end()); + sort(str2.begin(), str2.end()); + + for (int i = 0; i < n1; i++) + if (str1[i] != str2[i]) + return false; + return true; +} + +int main() { + string str1 = "listen"; + string str2 = "silent"; + + // Note that each letter need to be in same case. Otherwise, use toUpper Function before adding to function. + + cout << (Anagram(str1, str2) ? "Anagram" : "Not Anagram"); + +} \ No newline at end of file