Advertisement
Guest User

Untitled

a guest
May 20th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3. #include <iostream>
  4. #include <iomanip>
  5. #include <io.h>
  6. #include <fcntl.h>
  7. #include <locale>
  8. #include <string>
  9. #include <map>
  10. #include <windows.h>
  11.  
  12. using namespace std;
  13.  
  14. size_t hashing(wstring txt);
  15.  
  16. int main()
  17. {
  18. _setmode(_fileno(stdout), _O_WTEXT);
  19. _setmode(_fileno(stdin), _O_WTEXT);
  20. wstring txt;
  21. wcout << L"Введите текст:" << endl;
  22. getline(wcin, txt);
  23. multimap<size_t, wstring> hashTable;
  24. for (size_t begin = 0; begin < txt.length() - 1; begin += 10)
  25. hashTable.emplace(hashing(txt.substr(begin, 10)), txt.substr(begin, 10));
  26. wstring block;
  27. wcout << L"Введите искомый блок символов:" << endl;
  28. wcin >> block;
  29. auto findedHash = hashTable.equal_range(hashing(block));
  30. size_t countHashes = 0, countMatches = 0;
  31. for (auto ptrToElem = findedHash.first; ptrToElem != findedHash.second; ptrToElem++)
  32. {
  33. countHashes++;
  34. if (countHashes == 1)
  35. wcout << L"\nПо хэшу совпали:\n" << endl;
  36. wcout << (*ptrToElem).first << L" " << (*ptrToElem).second << endl;
  37. if ((*ptrToElem).second == block)
  38. countMatches++;
  39. }
  40. wcout << L"\nПо хэшу найдено " << countHashes << L" совпадений" << endl;
  41. wcout << L"По значению найдено " << countMatches << L" совпадений" << endl;
  42. system("pause");
  43. }
  44.  
  45. size_t hashing(wstring txt)
  46. {
  47. size_t hash = 0;
  48. for (wchar_t c : txt)
  49. hash += abs(c);
  50. return hash;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement