-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ03020.java
More file actions
43 lines (39 loc) · 1.16 KB
/
J03020.java
File metadata and controls
43 lines (39 loc) · 1.16 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
import java.util.*;
import java.math.*;
public class J03020 {
public static boolean check(String s) {
int l = 0;
int r = s.length() - 1;
while (l <= r) {
if (s.charAt(l) != s.charAt(r)) {
return false;
}
l++;
r--;
}
return true;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
LinkedHashMap<String, Integer> mp = new LinkedHashMap<>();
while (sc.hasNext()) {
String s = sc.next();
if (check(s)) {
if (mp.containsKey(s)) {
mp.put(s, mp.get(s) + 1);
} else {
mp.put(s, 1);
}
}
}
int maxx = -1;
for (Map.Entry<String, Integer> x : mp.entrySet()) {
maxx = Math.max(maxx, x.getKey().length());
}
for (Map.Entry<String, Integer> x : mp.entrySet()) {
if (x.getKey().length() == maxx) {
System.out.println(x.getKey() + " " + x.getValue());
}
}
}
}