1042 字符统计 (20分)
一、题目:
二、解析:
AC代码:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
*
* @author: ChangSheng
* @date: 2020年1月3日 下午4:42:03
*/
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int[] arr = new int[128];
String line = in.readLine();
for (int i = 0; i < line.length(); i++) {
char c = line.charAt(i);
if (c >= 'A' && c <= 'Z') {
arr[c+32]++;
continue;
}
arr[c]++;
}
int maxCount = 0;
char maxLetter = 0;
for (int i = 97; i < 97+26; i++) {
char c = (char) i;
if (arr[i] > maxCount) {
maxCount = arr[i];
maxLetter = (char) i;
}
}
System.out.print(maxLetter+" "+maxCount);
}
}
长生的梦呓
发布了99 篇原创文章 · 获赞 105 · 访问量 9247
私信
关注