P粉4706452222023-07-25 11:30:44
std::string decodeRLE(const std::string& rleString) {
std::string decodedString;
char previousChar = '\0'; // 为了重复出现的字符而存储前一个字符
for (const char& ch : rleString) { if ((ch & 0x80) == 0) { decodedString += ch; previousChar = ch; } else { unsigned char index = ch & 0x7F; unsigned char count = index + 3; decodedString.append(count, previousChar); } } return decodedString; } int main() { std::string rleString = "aAAb€Bc‚CƒdDDe€E"; std::string decodedString = decodeRLE(rleString); std::cout << "Decoded string: " << decodedString << std::endl; return 0; }