Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- #include <stdlib.h>
- #include <stdbool.h>
- #define N 50
- bool anagram(char* s, char* t){
- int a1[26]={0}, a2[26]={0};
- int i,j;
- while(*s && *t){
- i= *s - 'a';
- j= *t - 'a';
- a1[i] ++;
- a2[j] ++;
- s++;
- t++;
- }
- for(int k=0; k<26; k++){
- if(a1[k]!=a2[k]) return false;
- }
- return true;
- }
- int main() {
- char s[N], t[N];
- scanf("%s%s",s,t);
- if(strlen(s)!=strlen(t)){
- printf("%s and %s are Not Anagrams.");
- }
- else{
- if(anagram(s,t)){
- printf("%s and %s are Anagrams.",s,t);
- }
- else{
- printf("%s and %s are Not Anagrams.", s,t);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement