Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <iomanip>
- #include <io.h>
- #include <fcntl.h>
- #include <locale>
- #include <string>
- #include <map>
- #include <windows.h>
- using namespace std;
- size_t hashing(wstring txt);
- int main()
- {
- _setmode(_fileno(stdout), _O_WTEXT);
- _setmode(_fileno(stdin), _O_WTEXT);
- wstring txt;
- wcout << L"Введите текст:" << endl;
- getline(wcin, txt);
- multimap<size_t, wstring> hashTable;
- for (size_t begin = 0; begin < txt.length() - 1; begin += 10)
- hashTable.emplace(hashing(txt.substr(begin, 10)), txt.substr(begin, 10));
- wstring block;
- wcout << L"Введите искомый блок символов:" << endl;
- wcin >> block;
- auto findedHash = hashTable.equal_range(hashing(block));
- size_t countHashes = 0, countMatches = 0;
- for (auto ptrToElem = findedHash.first; ptrToElem != findedHash.second; ptrToElem++)
- {
- countHashes++;
- if (countHashes == 1)
- wcout << L"\nПо хэшу совпали:\n" << endl;
- wcout << (*ptrToElem).first << L" " << (*ptrToElem).second << endl;
- if ((*ptrToElem).second == block)
- countMatches++;
- }
- wcout << L"\nПо хэшу найдено " << countHashes << L" совпадений" << endl;
- wcout << L"По значению найдено " << countMatches << L" совпадений" << endl;
- system("pause");
- }
- size_t hashing(wstring txt)
- {
- size_t hash = 0;
- for (wchar_t c : txt)
- hash += abs(c);
- return hash;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement