Character Statistics 2Time limit:1000 Ms Memory limit:65536 KiB Submit statistic
Problem Description
Enter an English sentence to output the most frequently occurring characters and the number of occurrences in the sentence. Input
The input data contains multiple test instances, each of which is an English sentence that is no more than 100 in length and occupies one row. Output
Line-by-row output the most occurrences of the characters in each sentence and the number of occurrences (if there are multiple characters, output only the smallest ASCII character). Sample Input
I am a student
a good programming problem
ABCD ABCD ABCD
Sample Output
A 2
o 4
a 2
Hint
Source
Java Array initialization method: Java.util.Arrays.fill (array name, numeric)
Reference: https://blog.csdn.net/alenc/article/details/1500113
import java.util.*;
public class Main {public static void main (string[] args) {Scanner input = new Scanner (system.in); Char c[] = new char[] {' A ', ' B ', ' C ', ' d ', ' e ', ' f ', ' g ', ' h ', ' I ', ' j ', ' K ', ' l ', ' m ', ' n ', ' o ', ' P ', ' Q ', ' R ', ' s ', ' t ', ' u ', ' V ', ' w ', ' x ', ' y ', ' z ', ' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G ', ' H ', ' I ', ' J ', ' K ', ' L ', ' M ', ' N ', ' O ', ' P ', ' Q ', '
', ' R ', ' S ', ' T ', ' U ', ' V ', ' W ', ' X ', ' Y ', ' Z '};
while (Input.hasnext ()) {char arr[] = Input.nextline (). ToCharArray ();
int num[] = new int[52];
Arrays.fill (num, 0); the//arrays.fill () method is only suitable for initializing an array with the same value.
int sum = 0, t = 0;
for (int i = 0; i < arr.length. i++) {for (int j = 0; J <-J + +) {if (c[j] = = Arr[i]) {num[j]++;
if (Num[j] > sum) {sum = Num[j];
t = j;
} if (num[j] = = SUM) {if (c[t] > c[j]) t = j;
} break;
}} System.out.printf ("%c%d\n", c[t], sum); }
}
}