Я использую unordered_set
в C ++ для проверки изограммных слов.
struct CustomHasher {
size_t operator()(const char& c) const;
};
// This hashing function should take the given character c and return an integer
// representing the hash value. This will be computed by the position of a-z,
// where a=>0, b=>1, and so on.
size_t CustomHasher::operator()(const char& c) const {
size_t i = tolower(c) - 'a';
return i;
}
void add_multiset(const string& s,
unordered_multiset<char, CustomHasher>* ms) {
for (int i = 0; i < s.length(); i++)
ms->insert(tolower(s[i]));
}
// inside main function
unordered_multiset<char, CustomHasher> ms;
add_multiset("hello", &ms);
Что не так с моим кодом? когда я проверяю вывод: ms.bucket('l')
я должен получить 11, но вместо этого я получаю 7
Также ms.bucket('o')
Я получаю 6, но вместо этого я должен получить 14
Что не так с моим кодом?