poj 1782 Run Length Encoding

poj 1782 Run Length Encoding,第1张

poj 1782 Run Length Encoding
#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;#define maxl 1005char st[maxl];char ans[maxl];void work(){    int len = strlen(st);    int i = 0;    int l = 0;    int r;    while (l < len)    {        r = l + 1;        if (r < len && st[r] == st[l])        { while (r < len && st[r] == st[l] && r - l < 9)     r++; ans[i++] = '0' + r - l; ans[i++] = st[l]; l = r;        }else        { while (r < len &&((r + 1 < len && st[r] != st[r + 1]) || r == len - 1))     r++; ans[i++] = '1'; for (int j = l; j < r; j++) {     if (st[j] == '1')         ans[i++] = '1';     ans[i++] = st[j]; } ans[i++] = '1'; l = r;        }    }    ans[i] = '';    printf("%sn", ans);}int main(){    while (gets(st))    {        work();    }    return 0;}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4929352.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-13
下一篇 2022-11-13

发表评论

登录后才能评论

评论列表(0条)

保存