Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <deque>
- #include <fstream>
- #include <sstream>
- #include <string>
- #include <unordered_map>
- #include <utility>
- #include <vector>
- std::string get_string(const std::deque<std::string>& dq) {
- std::stringstream ss;
- for (const auto& str : dq) {
- ss << str;
- }
- return ss.str();
- }
- int main() {
- std::ifstream in("input.txt");
- std::ofstream out("output.txt");
- size_t word_cnt, row_len;
- in >> word_cnt >> row_len;
- if (word_cnt < row_len) {
- return 0;
- }
- std::unordered_map<std::string, size_t> freq;
- std::deque<std::string> cur_row;
- for (size_t i = 0; i < word_cnt; ++i) {
- std::string word;
- in >> word;
- cur_row.push_back(word);
- auto ss = get_string(cur_row);
- if (i + 1 == row_len) {
- ++freq[get_string(cur_row)];
- cur_row.pop_front();
- }
- }
- std::vector<std::pair<size_t, std::string>> freq_vec;
- for (const auto& [row, times] : freq) {
- freq_vec.push_back({times, row});
- }
- std::sort(freq_vec.begin(), freq_vec.end());
- for (const auto& [times, row] : freq_vec) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement