-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanagram.java
58 lines (56 loc) · 904 Bytes
/
anagram.java
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
53
54
55
56
57
58
import java.io.*;
import java.util.*;
class anagram
{
public static void main(String[] args)
{
Scanner kb=new Scanner(System.in);
int num=kb.nextInt();
if(num>0&&num<1001)
{
String str[]=new String[num];
for(int i=0;i<num;i++)
{
str[i]=kb.next();
}
int res=0;
for(int j=0;j<num;j++)
{
int flag=check(str[j]);
if(flag==1)
{res++;}
}
System.out.println(res);
}
}
public static int check(String str)
{
String st="kabali";
if(str.length()!=st.length())
{
return 0;
}
else
{
char ch1[]=new char[str.length()];
char ch2[]=new char[str.length()];
for(int i=0;i<str.length();i++)
{
ch1[i]=str.charAt(i);
ch2[i]=st.charAt(i);
}
Arrays.sort(ch1);
Arrays.sort(ch2);
int flag=1;
for(int k=0;k<str.length();k++)
{
if(ch1[k]!=ch2[k])
{
flag=0;
break;
}
}
return flag;
}
}
}