TreeMap解决
字串的连接最长路径查找
http://www.nowcoder.com/questionTerminal/5af18ba2eb45443aa91a11e848aa6723
用TreeMap可解决排序问题,键为字符串,值为字符串的个数。
import java.util.Map; import java.util.Scanner; import java.util.TreeMap; public class Main{ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Map<String,Integer> map = new TreeMap<String,Integer>(); int n = scanner.nextInt(); for(int i = 0;i < n;i ++) { String s = scanner.next(); map.put(s,map.getOrDefault(s, 0) + 1); } for (Map.Entry<String, Integer> entry : map.entrySet()) { for(int i = 0;i < entry.getValue();i ++) { System.out.println(entry.getKey()); } } scanner.close(); } }