Код решения:
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main() {
std::ifstream file("message.txt");
string txt((istreambuf_iterator<char>(file)), istreambuf_iterator<char>());
file.close();
int n = 3;
vector<std::string> txt3gram;
for (size_t i = 0; i < txt.length(); i += n) {
txt3gram.push_back(txt.substr(i, n));
}
string decoded_text;
for (const auto& chunk : txt3gram) {
decoded_text += chunk[2];
decoded_text += chunk[0];
decoded_text += chunk[1];
}
cout << decoded_text << endl;
return 0;
}
Видео выполнения: