我正在寻找一种算法,可以将英语单词转换为唯一的整数,英语词典中大约有500000个单词,例如,我想比较整数,而不是字符串:
#include <iostream>
#include <vector>
#include <string>
int convert_word_to_int(const std::string& word) {
// some allgorithm that i am looking for
}
int main()
{
std::string s1 = "wonderful";
std::string s2 = "flower";
std::string s3 = "car";
std::vector<int> v;
v.push_back(convert_word_to_int(s1));
v.push_back(convert_word_to_int(s2));
v.push_back(convert_word_to_int(s3));
std::string word = "car";
int number = convert_word_to_int(word);
for (int i = 0; i < v.size(); ++i) {
if (number == v[i]) {
std::cout << "The word is exists" << std::endl;
}
else {
std::cout << "The word is not exists" << std::endl;
}
}
return 0;
}