P粉4706452222023-07-25 11:30:44
std::string decodeRLE(const std::string& rleString) {
std::string decodedString;
char previousChar = '\0'; // Store the previous character for repeated characters
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; }