虽然是水题但想了好久。。。太菜了
两个map,一个计数,一个放标准化和原串的映射,set把选出的字符串添加并排序。
import java.util.*;
public class UVA156 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
Map<String,Integer> map=new HashMap<>();
Map<String,String> map1=new HashMap<>();
Set<String> set=new TreeSet<>();
while(true){
String[] s =sc.nextLine().split(" ");
if(s[0].equals("#"))break;
for (String item : s) {
char[] c = item.toLowerCase().toCharArray();
StringBuilder s1 = new StringBuilder();
Arrays.sort(c);
for (char value : c) {
s1.append(value);
}
if(!map.containsKey(s1.toString())){
map.put(s1.toString(), 1);
map1.put(s1.toString(),item);
}else{
map.put(s1.toString(),map.get(s1.toString())+1);
}
}
}
//遍历map
for(Map.Entry<String, Integer> entry:map.entrySet()){
if(entry.getValue()==1){
set.add(map1.get(entry.getKey()));
}
}
//遍历set
for (String s:set
) {
System.out.println(s);
}
}
}