-
Notifications
You must be signed in to change notification settings - Fork 7
/
anagram
52 lines (48 loc) · 1.28 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
49
50
51
52
import java.util.Scanner;
public class anagram {
static boolean isAnagram(String a, String b)
{
// Complete the function
if(a.length()!=b.length())
return false;
int l=a.length();
a=a.toLowerCase();
b=b.toLowerCase();
System.out.println(a+"\n"+b);
char w1[]=new char[l];
char w2[]=new char[l];
int f1[]=new int[l];
int f2[]=new int[l];
for(int i=0;i<l;++i)
{
int p=0;
for(int j=0;j<i;++j)
{
if(a.charAt(j)==a.charAt(i))
p=1;
}
if(p!=1)
for(int j=0;j<l;++j)
{
if(a.charAt(j)==a.charAt(i))
++f1[i];
if(b.charAt(j)==a.charAt(i))
++f2[i];
}
}
for(int i=0;i<l;++i)
{
if(f1[i]!=f2[i])
return false;
}
return true;
}
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" );
}
}