Skip to content

Instantly share code, notes, and snippets.

@kurianbenoy
Created November 7, 2018 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurianbenoy/6b80b9fd87af1258fc3294418d088dc8 to your computer and use it in GitHub Desktop.
Save kurianbenoy/6b80b9fd87af1258fc3294418d088dc8 to your computer and use it in GitHub Desktop.
#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