-
Notifications
You must be signed in to change notification settings - Fork 0
/
J03020_TimTuThuanNghichDaiNhat.java
46 lines (42 loc) · 1.24 KB
/
J03020_TimTuThuanNghichDaiNhat.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
import java.util.*;
import java.io.*;
import java.math.*;
public class J03020_TimTuThuanNghichDaiNhat {
public static boolean check(String s) {
char[] c = s.toCharArray();
int l = 0, r = c.length - 1;
while (l < r) {
if (c[l++] != c[r--]) {
return false;
}
}
return true;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
TreeMap<String, Integer> tm = new TreeMap<>();
LinkedHashSet<String> ts = new LinkedHashSet<>();
ArrayList<String> a = new ArrayList<>();
int max = 0;
while (sc.hasNext()) {
String k = sc.next();
if (check(k)) {
max = max > k.length() ? max : k.length();
if (tm.containsKey(k)) {
tm.put(k, tm.get(k) + 1);
} else {
tm.put(k, 1);
}
ts.add(k);
}
}
for (String x : ts) {
if (x.length() == max) {
a.add(x);
}
}
for (String x : a) {
System.out.println(x + " " + tm.get(x));
}
}
}