HashTree红黑树搞定
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while(in.hasNextLine()){
String s=in.nextLine();
solve(s);
}
}
public static void solve(String s){
char[] str = s.toCharArray();
Map<Character,Integer> map = new TreeMap<>();
for(char i:str){
if(!map.containsKey(i)){
map.put(i,1);
}else{
int value = map.get(i);
map.put(i,value+1);
}
}
for(Map.Entry<Character,Integer> entry : map.entrySet()){
System.out.print(entry.getKey());
System.out.print(entry.getValue());
}
}
}

京公网安备 11010502036488号