-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspell.cc
39 lines (36 loc) · 903 Bytes
/
spell.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include "dictionary.h"
using std::string;
using std::vector;
using std::cin;
using std::cout;
using std::endl;
void check_word(const string& word, const Dictionary& dict)
{
if (dict.contains(word)) {
cout << "Correct." << endl;
} else {
vector<string> suggestions = dict.get_suggestions(word);
if (suggestions.empty()) {
cout << "Wrong, no suggestions." << endl;
} else {
cout << "Wrong. Suggestions:" << endl;
for (const auto& w : suggestions) {
cout << " " << w << endl;
}
}
}
}
int main() {
Dictionary dict;// = new Dictionary(25);
string word;
while (cin >> word) {
transform(word.begin(), word.end(), word.begin(), ::tolower);
check_word(word, dict);
}
return 0;
}