C 示例:行程长度编码:RLE 压缩、解压与往返校验
一个完整的 RLE 压缩/解压工具:把连续重复字符编码成「次数+字符」,再解码还原,并对三组输入做往返一致性校验。支持两位数计数(如 12W)与无重复字符的边界情况,是文本/二进制预处理的基础手法。
🖥 在线运行GCC 10.2 · C11 标准 · 点 ▶ 运行 · 复制代码
🖨 参考输出与在线运行结果一致(标准 C11 环境)
input : AAABBBCCCD encoded : 3A3B3C1D decoded : AAABBBCCCD roundtrip: OK input : AB encoded : 1A1B decoded : AB roundtrip: OK input : WWWWWWWWWWWW encoded : 12W decoded : WWWWWWWWWWWW roundtrip: OK
🧩 继续学习