Advertisement
4doorsmorehories

anagram

Apr 18th, 2024
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5. #include <stdbool.h>
  6. #define N 50
  7. bool anagram(char* s, char* t){
  8.     int a1[26]={0}, a2[26]={0};
  9.     int i,j;
  10.     while(*s && *t){
  11.         i= *s - 'a';
  12.         j= *t - 'a';
  13.         a1[i] ++;
  14.         a2[j] ++;
  15.         s++;
  16.         t++;
  17.     }
  18.     for(int k=0; k<26; k++){
  19.         if(a1[k]!=a2[k]) return false;
  20.     }
  21.     return true;
  22. }
  23. int main() {
  24.  
  25.     char s[N], t[N];
  26.     scanf("%s%s",s,t);
  27.     if(strlen(s)!=strlen(t)){
  28.         printf("%s and %s are Not Anagrams.");
  29.     }
  30.     else{
  31.         if(anagram(s,t)){
  32.             printf("%s and %s are Anagrams.",s,t);
  33.         }
  34.         else{
  35.             printf("%s and %s are Not Anagrams.", s,t);
  36.         }
  37.        
  38.     }
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement