Maxim_Leo

Untitled

May 5th, 2022
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <list>
  4. #include <vector>
  5. #include <iterator>
  6. using namespace std;
  7.  
  8. vector< list<string>*> hash_table;
  9.  
  10. void hash_(string word) {
  11. int sum = 0;
  12. int num = 0;
  13. hash_table.resize(10);
  14. char numbers1[] = { '0','А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я' };
  15. char numbers2[] = { '0','а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ъ', 'ы', 'ь', 'э', 'ю', 'я' };
  16.  
  17. for (int k = 0; k < word.size(); k++) {
  18. for (int m = 0; m < sizeof(numbers1); m++) {
  19. if (word[k] == numbers1[m]) {
  20. sum += m;
  21. num++;
  22. }
  23. }
  24. for (int t = 0; t < sizeof(numbers2); t++) {
  25. if (word[k] == numbers2[t]) {
  26. sum += t;
  27. num++;
  28. }
  29. }
  30.  
  31. }
  32. sum = sum % 10;
  33.  
  34. list<string> list1;
  35. list1.push_front(word);
  36. cout << *list1.begin();
  37. list<string>* ptr = &list1;
  38. int count;
  39. hash_table[sum] = ptr;
  40. cout << "Слово " << num << " : " << sum << endl;
  41. sum = 0;
  42. }
  43. int getHash(string word) {
  44. int sum = 0;
  45. int num = 0;
  46. char numbers1[] = { '0','А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я' };
  47. char numbers2[] = { '0','а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ъ', 'ы', 'ь', 'э', 'ю', 'я' };
  48.  
  49. for (int k = 0; k < word.size(); k++) {
  50. for (int m = 0; m < sizeof(numbers1); m++) {
  51. if (word[k] == numbers1[m]) {
  52. sum += m;
  53. num++;
  54. }
  55. }
  56. for (int t = 0; t < sizeof(numbers2); t++) {
  57. if (word[k] == numbers2[t]) {
  58. sum += t;
  59. num++;
  60. }
  61. }
  62.  
  63. }
  64. sum = sum % 10;
  65. return sum;
  66. }
  67.  
  68. auto string_find(string word) {
  69. int num = getHash(word);
  70. list<string> ::iterator it;
  71. cout<< *hash_table[num]->begin();
  72. return 0;
  73. }
  74. int main()
  75. {
  76. setlocale(LC_ALL, "Russian");
  77. cout << "Задание 1: " << endl;
  78. vector<string> words = { "Ноутбук","Компьютер","Телефон","Планшет","Приставка","Умные часы","Наушники" };
  79. //hash1(words, 7, listwords);
  80. for (int i = 0; i < 7; i++) {
  81. hash_(words[i]);
  82. }
  83. string_find(words[0]);
  84. cout << endl << "Задание 2: " << endl;
  85.  
  86. return 0;
  87. }
  88.  
  89.  
  90.  
Advertisement
Add Comment
Please, Sign In to add comment