Advertisement
TrickmanOff

Untitled

Sep 19th, 2020
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include <algorithm>
  2. #include <deque>
  3. #include <fstream>
  4. #include <sstream>
  5. #include <string>
  6. #include <unordered_map>
  7. #include <utility>
  8. #include <vector>
  9.  
  10. std::string get_string(const std::deque<std::string>& dq) {
  11. std::stringstream ss;
  12. for (const auto& str : dq) {
  13. ss << str;
  14. }
  15. return ss.str();
  16. }
  17.  
  18. int main() {
  19. std::ifstream in("input.txt");
  20. std::ofstream out("output.txt");
  21.  
  22. size_t word_cnt, row_len;
  23. in >> word_cnt >> row_len;
  24.  
  25. if (word_cnt < row_len) {
  26. return 0;
  27. }
  28.  
  29. std::unordered_map<std::string, size_t> freq;
  30.  
  31. std::deque<std::string> cur_row;
  32.  
  33. for (size_t i = 0; i < word_cnt; ++i) {
  34. std::string word;
  35. in >> word;
  36. cur_row.push_back(word);
  37.  
  38. auto ss = get_string(cur_row);
  39. if (i + 1 == row_len) {
  40. ++freq[get_string(cur_row)];
  41. cur_row.pop_front();
  42. }
  43. }
  44.  
  45. std::vector<std::pair<size_t, std::string>> freq_vec;
  46. for (const auto& [row, times] : freq) {
  47. freq_vec.push_back({times, row});
  48. }
  49. std::sort(freq_vec.begin(), freq_vec.end());
  50. for (const auto& [times, row] : freq_vec) {
  51.  
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement