题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/5af18ba2eb45443aa91a11e848aa6723
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); try{ Map<String,Integer> map = new TreeMap<>(); int n = in.nextInt(); while(n>0){ String str = in.next(); if(map.containsKey(str)){ map.put(str,(Integer)map.get(str) + 1); }else{ map.put(str,1); } n--; } for(String i : map.keySet()){ if(map.get(i) > 1){ for(int j = 1; j <= map.get(i) ;j++){ System.out.println(i); } }else{ System.out.println(i); } } }catch(InputMismatchException e){ System.out.print("你的输入有误"); }finally{ if(in != null){ in.close(); } } } }