import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()) {
String s = sc.nextLine();
Map<Integer,Integer> map = new HashMap<>();
int max = -1;
int max_index = -1;
for(int i = 0 ; i < s.length() ; i++) { // 遍历字符串
int n = s.charAt(i) - '0';
if(map.containsKey(n)) {
map.put(n,map.get(n) + 1);
if(max <= map.get(n)) { // 更新最大值
max = map.get(n);
max_index = n;
}
} else {
map.put(n, 1);
}
}
// 输出
for(int i = max ; i > 0 ; i--) {
for(int j = 0 ; j < 10 ; j++) {
if(map.containsKey(j)) {
if(i <= map.get(j)) {
System.out.print("*");
} else {
System.out.print(" ");
}
} else {
System.out.print(" ");
}
}
System.out.println();
}
System.out.println("0123456789");
}
}
}
牛客网 PAT乙级练习题 1031 直方图 Java
最新推荐文章于 2021-12-08 01:12:44 发布