From a614ae1052a111e20d357e54a0e25941aac99d49 Mon Sep 17 00:00:00 2001 From: Mansi Katiyar Date: Sun, 31 Oct 2021 20:03:40 +0530 Subject: [PATCH 1/2] Added Hamming.c --- Hamming.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Hamming.c diff --git a/Hamming.c b/Hamming.c new file mode 100644 index 0000000..4ea9ce4 --- /dev/null +++ b/Hamming.c @@ -0,0 +1,42 @@ +#include +#include +void main() +{ + int d,c,i, length, count = 0,n; + int s1[100], s2[100]; + printf("length of s1 and s2 \n"); + scanf("%d",&n); + printf("Enter s1 : "); + for(i=0;i Date: Sun, 31 Oct 2021 20:22:30 +0530 Subject: [PATCH 2/2] added anagram.cpp --- anagram.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 anagram.cpp diff --git a/anagram.cpp b/anagram.cpp new file mode 100644 index 0000000..b9119be --- /dev/null +++ b/anagram.cpp @@ -0,0 +1,49 @@ +// C++ program to check if two strings +// are anagrams of each other +#include +using namespace std; +#define NO_OF_CHARS 256 + +bool areAnagram(char* str1, char* str2) +{ + // Create a count array and initialize all values as 0 + int count[NO_OF_CHARS] = { 0 }; + int i; + + // For each character in input strings, increment count + // in the corresponding count array + for (i = 0; str1[i] && str2[i]; i++) { + count[str1[i]]++; + + count[str2[i]]--; + + } + + // If both strings are of different length. Removing + // this condition will make the program fail for strings + // like "aaca" and "aca" + if (str1[i] || str2[i]) + return false; + + // See if there is any non-zero value in count array + for (i = 0; i < NO_OF_CHARS; i++) + if (count[i]) + return false; + return true; +} + +// Driver code +int main() +{ + char str1[] = "geeks@forgeeks"; + char str2[] = "for@geeksgeeks"; + + // Function call + if (areAnagram(str1, str2)) + cout << "The two strings are anagram of each other"; + else + cout << "The two strings are not anagram of each " + "other"; + + return 0; +}