组合题5 个小题
已作答 0 / 5
(1)(字符串解码)“行程长度编码”(Run-Length Encoding)是一种无损压缩算法,常用于压缩重复字符较多的数据,以减少存储空间。假设原始字符串不包含数字字符。压缩规则如下:i) 如果原始字符串中一个字符连续出现 N 次(N≥2),在压缩字符串中它被表示为“字符 + 数字 N”。例如,编码 A12 代表 12 个连续的字符 A。ii) 如果原始字符串中一个字符只出现 1 次,在压缩字符串中它就表示为该字符本身。例如,编码 B 代表 1 个字符 B。
以下程序实现读取压缩字符串并输出其原始的、解压后的形式。试补全程序。
1#include <cctype>2#include <iostream>3#include <string>4using namespace std;5 6int main() {7 string z;8 cin >> z;9 string s = "";10 11 for (int i = 0; i < z.length(); ) {12 char ch = z[i];13 14 if (__①__ && isdigit(z[i + 1])) {15 i++;16 int count = 0;17 while (i < z.length() && isdigit(z[i])) {18 count = __②__;19 i++;20 }21 for (int j = 0; j < __③__; ++j) {22 s += ch;23 }24 } else {25 s += __④__;26 __⑤__;27 }28 }29 30 cout << s << endl;31 return 0;32}33 ③处应填( )