Advertisement
Guest User

Untitled

a guest
May 16th, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1.  
  2. Цепочка открыта. Сообщений: 3. Все сообщения прочитаны.
  3.  
  4. Перейти к содержимому
  5. Gmail используется с программой чтения с экрана
  6. in:sent
  7.  
  8. Поместить во входящие Ещё
  9. 56 из 111
  10.  
  11. Собеседование
  12. Входящие
  13. x
  14.  
  15. Rostyslav Miasnikov 10.06.2016
  16. Добрый день, Павел, Мы ждем Вас на собеседование 13 июня (понедельник) в 17-3...
  17.  
  18. Zelenko Pavel <zelenkopa@gmail.com>
  19. Прикрепленные файлы15.06.2016
  20. кому: Rostyslav
  21. Тестовое задание
  22.  
  23. 10 июня 2016 г., 16:03 пользователь Rostyslav Miasnikov <Rostyslav.Miasnikov@qaddress.com> написал:
  24.  
  25. Область прикрепленных файлов
  26.  
  27. Zelenko Pavel <zelenkopa@gmail.com>
  28. 15.06.2016
  29. кому: Rostyslav
  30. А, не увидел сообщения.
  31.  
  32. 15 июня 2016 г., 12:29 пользователь Zelenko Pavel <zelenkopa@gmail.com> написал:
  33.  
  34.  
  35. Нажмите здесь, чтобы Ответить или Переслать
  36. Использовано 0,72 ГБ (4%) из 15 ГБ
  37. Управление
  38. Условия - Конфиденциальность
  39. Последние действия в аккаунте: 9 мин. назад
  40. Открыто в другом месте Дополнительная информация
  41.  
  42.  
  43. #include <iostream>
  44. #include <string>
  45. #include <fstream>
  46. #include <unordered_map>
  47.  
  48. const std::string DICTIONARY_PATH = "input.txt";
  49. const std::string REQUESTS_PATH = "req.txt";
  50. const std::string OUTPUT_PATH = "output.txt";
  51.  
  52. class StringsStore
  53. {
  54. public:
  55. void AddString(const std::string& str);
  56. bool FindString(const std::string& str) const;
  57.  
  58. private:
  59. struct Node
  60. {
  61. Node() : finish(false) {}
  62. bool finish;
  63. std::unordered_map<char, Node> children;
  64. } root_;
  65. };
  66.  
  67. void StringsStore::AddString(const std::string& str)
  68. {
  69. Node * current = &root_;
  70.  
  71. for (char s : str)
  72. {
  73. if (current->children.find(s) == current->children.end())
  74. current->children.insert(std::make_pair(s, Node()));
  75. current = &current->children[s];
  76. }
  77.  
  78. current->finish = true;
  79. }
  80.  
  81. bool StringsStore::FindString(const std::string& str) const
  82. {
  83. const Node* current = &root_;
  84. for (char s : str)
  85. {
  86. const auto& child = current->children.find(s);
  87. if (child == current->children.end())
  88. return false;
  89.  
  90. current = &child->second;
  91. }
  92.  
  93. return current->finish;
  94. }
  95.  
  96. namespace StringsStoreHelper
  97. {
  98. StringsStore ReadFromFile(const std::string& path)
  99. {
  100. StringsStore store;
  101. std::ifstream infile(path);
  102. std::string line;
  103. while (std::getline(infile, line))
  104. store.AddString(line);
  105.  
  106. return store;
  107. }
  108. }
  109.  
  110.  
  111. int main()
  112. {
  113. StringsStore store = StringsStoreHelper::ReadFromFile(DICTIONARY_PATH);
  114.  
  115. std::ifstream reqfile(REQUESTS_PATH);
  116. std::ofstream outfile(OUTPUT_PATH);
  117.  
  118. std::string line;
  119. while (std::getline(reqfile, line))
  120. outfile << store.FindString(line) << "\n";
  121. return 0;
  122. }
  123. Source.cpp
  124. Отображается файл "Source.cpp"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement