题解 | #字符统计#
字符统计
http://www.nowcoder.com/practice/c1f9561de1e240099bdb904765da9ad0
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
while(scan.hasNext()){
String str = scan.nextLine();
int[] count = new int[500];
char[] ch = str.toCharArray();
int max = Integer.MIN_VALUE;
StringBuilder strb = new StringBuilder();
for(char c : ch){
// count[Integer.parseInt(String.valueOf(c))]++;
count[(int)c]++;
}
for(int i = 0; i<count.length; i++){
max = Math.max(max,count[i]);
}
for(int i = max; i>0; i--){
for(int j = 0; j<count.length; j++){
if(count[j] == i){
// strb.append(String.valueOf(j).charAt(0));
strb.append((char)j);
}
}
}
System.out.println(strb.toString());
}
scan.close();
}
}