Advertisement
Karim_Gabr

Untitled

Jun 24th, 2014
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.82 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int Anagram_Check( char X[] , char Y[] )
  4. {
  5.     int i , j;
  6.     int length_y = 0 , length_x = 0;
  7.  
  8.     i = 0;
  9.     j = 0;
  10.  
  11.     while ( X[i] != '\0'  )
  12.             length_x ++ , i ++  ;
  13.     while ( Y[j] != '\0'  )
  14.             length_y ++ , j ++  ;
  15.  
  16.     i = 0;
  17.     j = 0;
  18.  
  19.     while (i < length_y)
  20.     {
  21.         while (j < length_x)
  22.         {
  23.             if ( Y[i] == X[j] )
  24.             {
  25.                 X[j] = '-' ;
  26.                 break ;
  27.             }
  28.             j++;
  29.         }
  30.         if ( j == length_x ) return 0 ;
  31.         i ++;
  32.     }
  33.  
  34.     i = 0;
  35.  
  36.     while (i < length_x)
  37.     {
  38.         if ( X[i] != '-' ) return 0 ;
  39.         i++;
  40.     }
  41.  
  42.     return 1 ;
  43. }
  44.  
  45. int main()
  46. {
  47.     char X[] = "tea" ;
  48.     char Y[] = "eat" ;
  49.     printf("%d",Anagram_Check(X,Y));
  50.     return 0 ;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement