题解 | #字符串归一化#
字符串归一化
https://www.nowcoder.com/practice/6d5e036defdf408681376a4a9d4930ff
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());
}
}
}
文远知行公司福利 582人发布