-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacterCount.java
More file actions
33 lines (33 loc) · 884 Bytes
/
CharacterCount.java
File metadata and controls
33 lines (33 loc) · 884 Bytes
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
import java.io.*;
import java.lang.*;
import java.util.*;
public class CharacterCount
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
String s=sc.next();
int len=s.length();
int size=26;
int freq[]=new int[size];
for(int i=0;i<26;i++)
freq[i]=0;
for(int i=0;i<len;i++){
freq[s.charAt(i)-'a']++;
}
int flag=0;
for(int i=0;i<26;i++){
if(freq[i]>1){
System.out.printf("%c=%d ",(char)(i+'a'),freq[i]);
flag=1;
}
}
if(flag!=1)
System.out.println(-1);
else
System.out.println();
}
}
}