为什么不能用treeset public static void main(String[] args) { Scanner scanner=new Scanner(System.in); String str = scanner.next(); int k = scanner.nextInt(); Set<String> set=new TreeSet<>(); for (int i = 0; i < str.length(); i++) { for (int j = i+1; j <= str.length(); j++) { set.add(str.substring(i,j)); } } Iterator<String> iterator = set.iterator(); List<String>list=new ArrayList<>(); int tmp=k; while (iterator.hasNext()&&tmp>=1) { list.add(iterator.next()); tmp--; } System.out.println(list.get(k-1)); }
点赞 1

相关推荐

牛客网
牛客企业服务