aaabbc
a3b2c1
void string_q14_compress_string() {
string text = "aaabbccccdd";
string compressed = "";
cout << "Original: " << text << endl;
int i = 0;
while(i < text.length()) {
char current = text[i];
int count = 0;
// Count consecutive same characters
while(i < text.length() && text[i] == current) {
count++;
i++;
}
compressed += current;
compressed += to_string(count);
}
cout << "Compressed: " << compressed << endl;
}
void string_q14_compress_string() {
string text = "aaabbccccdd";
string compressed = "";
cout << "Original: " << text << endl;
int i = 0;
while(i < text.length()) {
char current = text[i];
int count = 0;
// Count consecutive same characters
while(i < text.length() && text[i] == current) {
count++;
i++;
}
compressed += current;
compressed += to_string(count);
}
cout << "Compressed: " << compressed << endl;
}