Created
November 7, 2018 17:00
-
-
Save kurianbenoy/6b80b9fd87af1258fc3294418d088dc8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
void main() | |
{ | |
int n,i,j; | |
char a[100][100]; | |
scanf("%d",&n); | |
for(i=0;i<=n;i++) | |
gets(a[i]); | |
for(i=0;i<=n;i++) | |
{ | |
for(j=i+1;j<=n;j++) | |
{ | |
if(check_anagram(a[i],a[j])==1) | |
printf("\n%s %s",a[i],a[j]); | |
} | |
} | |
} | |
int check_anagram(char a[],char b[]) | |
{ | |
int first[26]={0}, second[26]={0}, c=0; | |
while(a[c] != '\0') | |
{ | |
first[a[c]-'a']++; | |
c++; | |
} | |
c = 0; | |
while (b[c] != '\0') | |
{ | |
second[b[c]-'a']++; | |
c++; | |
} | |
// Comparing frequency of characters | |
for (c = 0; c < 26; c++) | |
{ | |
if (first[c] != second[c]) | |
return 0; | |
} | |
return 1; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment