【发布时间】:2018-03-22 19:04:44
【问题描述】:
我是这个地方的新手,所以我可能不会清楚地问我的问题。但我确实需要帮助。所以我的作业是用 C++ 创建一个拼写检查器,它接受一个文本文件并将其与另一个字典文本文件进行比较。我有一个特定的 sn-p 代码需要解决。我创建了一个帮助函数 isValidWord,它接收包含容器 unordered_set 和字符串的字典。如果字符串与字典中的单词匹配,该函数将返回 true。我只会告诉你我到目前为止所拥有的。我的问题是字符串与库中的所有内容都不匹配,只检查字典中的一些内容。
#include <unordered_set>
#include <string>
bool isValidWord(std::unordered_set<std::string> dictionary, std::string& word) {
std::unordered_set<std::string>::iterator it;
for (it = dictionary.begin(); it != dictionary.end(); ++it) {
if (word == *it) {
return true;
}
}
return false;
}
【问题讨论】:
-
不匹配的原因与字母的CASE有关吗?
-
你能展示一个字符串与所有内容都不匹配的示例输入吗?
-
@CodeGorilla 案例问题已经解决
-
@SebastianStern 当字典有 80k+ 个单词时,字符串只会检查字典中的 2 个单词
-
请也通过引用传递字典,你不想通过值传递它
bool isValidWord(std::unordered_set<std::string>& dictionary...
标签: c++ string iterator unordered-set