-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgame.java
More file actions
46 lines (41 loc) · 1.29 KB
/
game.java
File metadata and controls
46 lines (41 loc) · 1.29 KB
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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class game {
public static void games() throws IOException{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int input = Integer.parseInt(reader.readLine());
int i=0;
String alpha = "abcdefghijklmnopqrstuvwxyz";
while(i<input){
int[] num = new int[26];
String k = reader.readLine();
for(int j=0;j<k.length();j++){
char x = k.charAt(j);
int index = alpha.indexOf(x);
num[index]++;
}
int max=0;
int mindex=0;
int count =0;
int e;
for (e=0;e<26;e++){
if(max < num[e]){
max = num[e];
mindex = e;
}
count = count + num[e];
}
if((count-max)<max){
System.out.println(alpha.charAt(mindex));
}
else{
System.out.println(-1);
}
i++;
}
}
public static void main(String[] args) throws IOException{
games();
}
}