import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String str = scanner.next(); String subStr = str; //两层循环使得各种字串情况可以详尽 for (int i = 0; i < str.length(); i++) { for (int j = i; j < str.length(); j++) { if (check(str.substring(i,j+1),str)){ if (str.substring(i,j+1).length() < subStr.length()){ subStr = str.substring(i,j+1); } } } } System.out.println(subStr); } //检查str中的每一个字符是不是都可以在newSubStr中找到 public static boolean check(String newSubStr,String str){ for (int i = 0; i < str.length(); i++) { if (newSubStr.indexOf(str.charAt(i)) == -1){ return false; } } return true; } }