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 +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; +}