#include <stdio.h>
#include <stdlib.h>
// #include <string.h>
char *func(char *s)
{
char *inp = s; // indata pointer
char *rData
= (char *)malloc(100 * sizeof(char)); // returning data area allocate char *r2 = rData; // returning data pointer
while (*s) { // reach to indata end?
while (*s == *inp) ++inp;
*r2++ = '0' + inp - s; // count set
*r2++ = *s; // char set
s = inp; // indata pointer shift
}
return rData;
}
int main()
{
char s[] = "1"; // initial indata
char *p = s;
int i;
for (i = 0; i < 10; ++i) {
p = func(p);
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KLy8gI2luY2x1ZGUgPHN0cmluZy5oPgoKY2hhciAqZnVuYyhjaGFyICpzKQp7CiAgY2hhciAqaW5wID0gczsgLy8gaW5kYXRhIHBvaW50ZXIKICBjaGFyICpyRGF0YSA9IChjaGFyICopbWFsbG9jKDEwMCAqIHNpemVvZihjaGFyKSk7IC8vIHJldHVybmluZyBkYXRhIGFyZWEgYWxsb2NhdGUKICBjaGFyICpyMiA9IHJEYXRhOyAvLyByZXR1cm5pbmcgZGF0YSBwb2ludGVyCiAgd2hpbGUgKCpzKSB7IC8vIHJlYWNoIHRvIGluZGF0YSBlbmQ/CiAgICB3aGlsZSAoKnMgPT0gKmlucCkgKytpbnA7CiAgICAqcjIrKyA9ICcwJyArIGlucCAtIHM7IC8vIGNvdW50IHNldAogICAgKnIyKysgPSAqczsgLy8gY2hhciBzZXQKICAgIHMgPSBpbnA7IC8vIGluZGF0YSBwb2ludGVyIHNoaWZ0CiAgfQogIHJldHVybiByRGF0YTsKfQoKaW50IG1haW4oKQp7CiAgY2hhciBzW10gPSAiMSI7IC8vIGluaXRpYWwgaW5kYXRhCiAgY2hhciAqcCA9IHM7CiAgaW50IGk7CiAgcHJpbnRmKCIlc1xuIiwgcCk7CiAgZm9yIChpID0gMDsgaSA8IDEwOyArK2kpIHsKICAgIHAgPSBmdW5jKHApOwogICAgcHJpbnRmKCIlc1xuIiwgcCk7CiAgfQogIHJldHVybiAwOwp9Cg==