题解 | #字符串归一化#
字符串归一化
https://www.nowcoder.com/practice/6d5e036defdf408681376a4a9d4930ff
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); HashMap<Character, Integer> map = new HashMap<>(); for(int i = 0; i < s.length(); i++) { char c = s.charAt(i); map.put(c, map.getOrDefault(c, 0) + 1); } Collection<Character> keySet = map.keySet(); ArrayList list = new ArrayList(keySet); Collections.sort(list); for(int j = 0; j < list.size(); j++) { System.out.print(list.get(j)); System.out.print(map.get(list.get(j))); } } }