-
Notifications
You must be signed in to change notification settings - Fork 354
/
Copy pathanagram
48 lines (37 loc) · 1.08 KB
/
anagram
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
47
48
import java.util.Scanner;
public class MyClass {
static boolean isAnagram(String a, String b) {
// Complete the function
int p[]=new int[256];
int q[]=new int[256];
if(a.length()==b.length()) {
a=a.toUpperCase();
b=b.toUpperCase();
for(int i=0;i<a.length();i++) {
char c1=a.charAt(i);
int n=c1;
p[n]++;
}
for(int j=0;j<b.length();j++) {
char c2=b.charAt(j);
int m=c2;
q[m]++;
}
for(int k=0;k<256;k++){
if(p[k]!= q[k])
return false;
}
return true;
}
else
return false;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String a = scan.next();
String b = scan.next();
scan.close();
boolean ret = isAnagram(a, b);
System.out.println( (ret) ? "Anagrams" : "Not Anagrams" );
}
}