bluesky8059

410487033_ex6-1

Oct 27th, 2015
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.65 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main ()
  4.  {
  5.     char string1[100];
  6.     char string2[100];
  7.     int i,test=0;
  8.     int calstr1[26]={0},calstr2[26]={0};
  9.  
  10.     scanf("%s",string1);
  11.     scanf("%s",string2);
  12.  
  13.  
  14.     for (i=0; string1[i]!='\0' ;i++)
  15.     {
  16.       calstr1[string1[i]-'a']++;
  17.     }
  18.  
  19.     for (i=0; string2[i]!='\0'  ;i++)
  20.     {
  21.       calstr2[string2[i]-'a']++;
  22.     }
  23.  
  24.     for (i=0;i<=25;i++)
  25.     {
  26.        if (calstr1[i] !=calstr2[i])
  27.         test = 1;
  28.     }
  29.     if(test==0)
  30.         printf("'%s' and '%s' are anagrams.\n",string1,string2);
  31.     else
  32.         printf("'%s' and '%s' are not anagrams.\n",string1,string2);
  33.         return 0;
  34.  
  35.  }
Advertisement
Add Comment
Please, Sign In to add comment