In: Other
C++
#include <bits/stdc++.h> // imports all necessary headers
using namespace std;
int main()
{
string num;
int iter;
cin >> num >> iter;
for(int i = 1; i <= iter; i++) {
int len = num.size();
num += '?';
string temp = "";
int count = 0;
for(int j = 0; j < len; j++) {
if(num[j] == num[j + 1])
count++;
else {
count++;
temp += to_string(count);
temp += num[j];
count = 0;
}
}
cout << "iteration no " << i << " -- " << temp << endl;
num = temp;
}
return 0;
}