I am trying to use run length encoding.
Problem is ... a is 2 times
But cout show f is 3.
A is not showing in result.
And last element count var count stay equal to last element.
#include <iostream>
using namespace std;
int main()
{
string str = "aafffkhjskk";
int arr[100];
int count = 1;
cout << str << endl;
// print text on screen
for (int r = 0; r < str.length(); r++) {
// Str 0 strating point
for (int in = r; in < str.length(); in++) {
// r = in because increment finding element
if (str[r] == str[in]) {
count++;
}
else {
r += (count - 1);
// r value is equal to count
cout << " r " << r << " count " << count << endl;
cout << count << " ****** "
<< str[r] << endl;
count = 1;
// making count 1 again.
break;
}
}
} // for end here
}
question from:https://stackoverflow.com/questions/65949449/run-length-compression-only-for-loop