使用hashMap完成
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
while (sc.hasNextLine()) {
String str = sc.nextLine();
int length = str.length();
HashMap<Character,Integer> map = new HashMap<Character,Integer>();
HashSet<Character> set = new HashSet<Character>();
for (int i = 0; i < length; i++) {
if (!map.containsKey(str.charAt(i))) {
map.put(str.charAt(i), 1);
} else {
map.put(str.charAt(i), map.get(str.charAt(i)) + 1);
}
}
int min = length;
for(Map.Entry<Character,Integer> item : map.entrySet()) {
if (item.getValue() < min) {
min = item.getValue();
}
}
for(Map.Entry<Character,Integer> item : map.entrySet()) {
if (item.getValue() == min) {
str = str.replace(item.getKey().toString(),"");
}
}
System.out.println(str);
}
}
}