-
Notifications
You must be signed in to change notification settings - Fork 0
/
isAnagram.c
45 lines (34 loc) · 839 Bytes
/
isAnagram.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
bool isAnagram(char* s, char* t) {
int count[256] = {0};
int len1 = strlen(s);
int len2 = strlen(t);
if(len1 != len2) {
return false;
}
for(int i=0; i<len1; i++) {
count[s[i]]++;
count[t[i]]--;
}
for(int i=0; i<256; i++) {
if(count[i] != 0) {
return false;
}
}
return true;
}
int main() {
char s[100], t[100];
printf("Enter the first string: ");
scanf("%s", s);
printf("Enter the second string: ");
scanf("%s", t);
if(isAnagram(s, t)) {
printf("The second string is an anagram of the first string.");
} else {
printf("The second string is not an anagram of the first string.");
}
return 0;
}