-
Notifications
You must be signed in to change notification settings - Fork 0
/
Anagram.java
37 lines (37 loc) · 1013 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
package rank;
import java.util.*;
public class Anagram
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-- >0)
{
String ss=sc.next();
StringBuilder s=new StringBuilder(ss);
int c=0;
if(s.length()%2!=0)
{
System.out.println("-1");
}
else
{
for(int i=0;i<s.length()/2;i++)
{
for(int j=(s.length()/2);j<s.length();j++)
{
if(s.charAt(i)==s.charAt(j))
{
s.setCharAt(j,'0');
c++;
break;
}
}
//System.out.println(s);
}
System.out.println((s.length()/2-c));
}
}
}
}