1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| #include <iostream> #include <string> using namespace std;
string compress(const string &s) { int n = s.size(); string res; for (int i = 0, count = 0; i <= n; i++) { if (i == n || i > 0 && s[i] != s[i - 1]) { res.push_back(s[i - 1]); res += to_string(count); count = 0; } count++; } return res; }
int main() { string s; int n; cin >> s >> n; for (int i = 1; i < n; i++) { s = compress(s); } cout << s << endl; return 0; }
|