Set Spell checker
The simplest spell checker is the one based on a list of known words. Every word in the text is being searched for in this list and, if such word was not found, it is marked as erroneous.
Write such a spell checker.
The first line of the input contains dd – number of records in the list of known words. Next go dd lines containing one known word per line, next — the number ll of lines of the text, after which — ll lines of the text.
Write a program that outputs those words from the text that are not found in the dictionary (i.e. erroneous). Your spell checker should be case insensitive. The words are entered in an arbitrary order. Words, which are not found in the dictionary, should not be duplicated in the output.
Report a typo
Sample Input 1:
3
a
bb
cCc
2
a bb aab aba ccc
c bb aaa
Sample Output 1:
c
aab
aaa
aba
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner number = new Scanner(System.in);
Set<String> dict = new TreeSet<>();
Set<String> words = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
int nu = number.nextInt();
for (int i = 0; i < nu; i++) {
dict.add(number.next());
}
int lines = number.nextInt();
for (int i = 0; i <= lines; i++) {
words.addAll(Arrays.asList(number.nextLine().split(" ")));
}
words.removeAll(dict);
words.forEach(System.out::println);
}
}

浙公网安备 33010602011771号