Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- std::string findNTh(int x, int n) {
- std::string str = std::to_string(x);
- if (n == 1) {
- return str;
- }
- std::string prev = str;
- for (int iter = 2; iter <= n; iter++) {
- // добавим символ, чтобы отдельно не обрабатывать случай после выхода из цикла
- prev = prev + '&';
- int count = 1;
- std::string next;
- for (int i = 1; i < prev.size(); i++) {
- if (prev[i] != prev[i-1]) {
- next += static_cast<char>('0' + count);
- next += prev[i - 1];
- count = 1;
- } else {
- count++;
- }
- }
- prev = next;
- }
- return prev;
- }
- int main() {
- int x, n;
- std::cin >> x >> n;
- std::cout << findNTh(x, n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement