-
Notifications
You must be signed in to change notification settings - Fork 51
/
Anagrama.c
46 lines (45 loc) · 1003 Bytes
/
Anagrama.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
45
46
/*This program tests whether a word or phrase is an anagram of another one.
Sample Input:
Thats one small step for a man. One giant leap for mankind. Neil Armstrong
Thin man ran... makes a large stride... left planet... pins flag on moon... on to Mars!
Sample Output:
True
*/
#include <stdio.h>
#include <string.h>
int main(){
int k=1, i, f1[400]={0}, f2[400]={0};
char s1[10000], s2[10000];
scanf("%[^\n]",s1);
scanf(" %[^\n]",s2);
for(i=0;i<strlen(s1);i++){
if(s1[i]>='A' && s1[i]<='Z'){
s1[i] += 32;
}
}
for(i=0;i<strlen(s2);i++){
if(s2[i]>='A' && s2[i]<='Z'){
s2[i] += 32;
}
}
for(i=0;i<strlen(s1);i++){
if(s1[i]!='.' && s1[i]!=',' && s1[i]!='!' && s1[i]!='?' && s1[i]!=' '){
f1[s1[i]+94]++;
}
}
for(i=0;i<strlen(s2);i++){
if(s2[i]!='.' && s2[i]!=',' && s2[i]!='!' && s2[i]!='?' && s2[i]!=' '){
f2[s2[i]+94]++;
}
}
for(i=0;i<400;i++){
if(f1[i]==f2[i] && k==1){
k=1;
}else{
k=0;
}
}
if(k==1) printf("True");
else printf("False");
return 0;
}