源码 Java
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;import java.util.ArrayList;
import java.util.List;
import java.util.TreeSet;public class GuessWord {public Input input;@BeforeEachpublic void init() {input= new Input("bdni,wooood\nbind,wrong,wood");}@Testpublic void test() {String string = input.nextLine();String[] words = string.split(",");String[] answers = input.nextLine().split(",");List<String> wordList = new ArrayList<>();List<String> answerList = new ArrayList<>();for (String word : words) {wordList.add(dealWord(word));}for (String answer : answers) {answerList.add(dealWord(answer));}List<String> result = new ArrayList<>();for (int i = 0; i < wordList.size(); i++) {int index = findWord(answerList, wordList.get(i));if (index != -1) {result.add(answers[i]);} else {result.add("not found");}}System.out.println(String.join(",", result));}public int findWord(List<String> lists , String word) {for (int i = 0; i < lists.size(); i++) {if (lists.get(i).equals(word)) {return i;}}return -1;}public String dealWord(String word) {TreeSet<Character> set = new TreeSet<>();for (int i = 0; i < word.length(); i++) {set.add(word.charAt(i));}Character[] array = set.toArray(new Character[set.size()]);StringBuilder answer = new StringBuilder();for (int i = 0; i < array.length; i++) {answer.append(array[i]);}return answer.toString();}
}