更新
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import java.util.*;
|
||||
|
||||
public class P2975 {
|
||||
public static void main(String[] args) {
|
||||
Scanner in = new Scanner(System.in);
|
||||
StringBuilder all = new StringBuilder();
|
||||
if (in.hasNextLine()) {
|
||||
all.append(in.nextLine());
|
||||
while (in.hasNextLine()) {
|
||||
all.append('\n');
|
||||
all.append(in.nextLine());
|
||||
}
|
||||
}
|
||||
Map<Character, Integer> cnt = new HashMap<>();
|
||||
for (int i = 0; i < all.length(); i++) {
|
||||
char c = all.charAt(i);
|
||||
if (c == '\r' || c == '\n') continue;
|
||||
cnt.put(c, cnt.getOrDefault(c, 0) + 1);
|
||||
}
|
||||
char bestChar = 0;
|
||||
int best = -1;
|
||||
for (Map.Entry<Character, Integer> e : cnt.entrySet()) {
|
||||
char c = e.getKey();
|
||||
int v = e.getValue();
|
||||
if (v > best || (v == best && c < bestChar)) {
|
||||
best = v;
|
||||
bestChar = c;
|
||||
}
|
||||
}
|
||||
if (best < 0) {
|
||||
System.out.println();
|
||||
System.out.println(0);
|
||||
} else {
|
||||
System.out.println(bestChar);
|
||||
System.out.println(best);
|
||||
}
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.5 MiB |
Reference in New Issue
Block a user