RLE Encoding/Compression c++
C++
#include <iostream>
#include <string>
using namespace std;
// Perform Run Length Encoding (RLE) data compression algorithm
// on string str
string encode(string str)
{
// stores output string
string encoding = "";
int count;
for (int i = 0; str[i]; i++)
{
// count occurrences of character at index i
count = 1;
while (str[i] == str[i + 1])
count++, i++;
// append current character and its count to the result
encoding += to_string(count) + str[i];
}
return encoding;
}
int main()
{
string str = "ABBCCCD";
cout << encode(str);
return 0;
}
Also in C++:
- Title
- mysqli connect
- Category
- C++
- Title
- switch statement c++
- Category
- C++
- Title
- unsorted array to bst
- Category
- C++
- Title
- program to know if a number is prime
- Category
- C++
- Title
- convert integer to string c++
- Category
- C++
- Title
- ios_base::sync_with_stdio(false);cin.tie(NULL);
- Category
- C++
- Title
- how use global variables instead of local in c++
- Category
- C++
- Title
- differentialble programming
- Category
- C++
- Title
- git branch in my bash prompt
- Category
- C++
- Title
- c++ how to add something at the start of a vector
- Category
- C++
- Title
- how to avoid tle in c++
- Category
- C++
- Title
- c++ ros subscriber
- Category
- C++
- Title
- pionter in c++
- Category
- C++
- Title
- vector concat c++
- Category
- C++
- Title
- if vector contains value c++
- Category
- C++
- Title
- friend function in c++
- Category
- C++
- Title
- return function in cpp
- Category
- C++
- Title
- c++ cli convert string to string^
- Category
- C++
- Title
- how to delete something in an array c++
- Category
- C++
- Title
- pass vector by reference c++
- Category
- C++
- Title
- two elements with difference K in c++
- Category
- C++
- Title
- min heap priority queue c++
- Category
- C++
- Title
- cout console
- Category
- C++
- Title
- c++ sql
- Category
- C++
- Title
- user input c++
- Category
- C++
- Title
- sieve of eratosthenes c++
- Category
- C++
- Title
- pair in c++
- Category
- C++
- Title
- singleton c++
- Category
- C++
- Title
- qt graphics scene map cursor position
- Category
- C++
- Title
- fmod c++
- Category
- C++
- Title
- strchr function in c++
- Category
- C++
- Title
- comparing strings c++
- Category
- C++
- Title
- c++ function return array
- Category
- C++
- Title
- leveling system c++
- Category
- C++
- Title
- max three values c++
- Category
- C++
- Title
- remove element by index from vector c++
- Category
- C++
- Title
- modular exponentiation c++
- Category
- C++
- Title
- how to convert string into number
- Category
- C++
- Title
- Read multiple files(.txt) c++
- Category
- C++
- Title
- how to find length of string in c++
- Category
- C++
- Title
- power c++
- Category
- C++
- Title
- erase in set
- Category
- C++
- Title
- opencv compile c++
- Category
- C++
- Title
- c++ string to vector int
- Category
- C++
- Title
- c++ replace substrings
- Category
- C++
- Title
- binary search in set c++
- Category
- C++
- Title
- flake8 max line length
- Category
- C++
- Title
- findung the mode in c++
- Category
- C++
- Title
- how to measure program run time in c++
- Category
- C++
- Title
- repeating character in c++
- Category
- C++
- Title
- c++ movment
- Category
- C++
- Title
- How to find the suarray with maximum sum using divide and conquer
- Category
- C++
- Title
- how to cout in c++
- Category
- C++
- Title
- regexp_like oracle c++
- Category
- C++
- Title
- fast input output in c++
- Category
- C++
- Title
- split string at index c++
- Category
- C++
- Title
- c++ switch case statement
- Category
- C++
- Title
- how to sort an array according to another array c++
- Category
- C++
- Title
- passing array to function c++ pointer
- Category
- C++
- Title
- statement that causes a function to end in c++
- Category
- C++
- Title
- what is meaning of 64 bit integer in c++
- Category
- C++
- Title
- c++ code to print hello world
- Category
- C++
- Title
- convert int to string c++
- Category
- C++
- Title
- residuo en lenguaje c
- Category
- C++
- Title
- range based for loop c++ with reference
- Category
- C++
- Title
- is TLE means my code is correct but taking more time to computr
- Category
- C++
- Title
- how to declare a function in c++
- Category
- C++
- Title
- c++ ros publisher
- Category
- C++
- Title
- c++ max of array
- Category
- C++
- Title
- map arduino
- Category
- C++
- Title
- create a bitset of 1024 bits,
- Category
- C++
- Title
- placement new c++
- Category
- C++
- Title
- border radius layout android xml
- Category
- C++
- Title
- pause the console c++
- Category
- C++
- Title
- substr c++
- Category
- C++
- Title
- c++ program to input and print text using Dynamic Memory Allocation.loop
- Category
- C++
- Title
- system("pause") note working c++
- Category
- C++
- Title
- how to declare a vector in c++
- Category
- C++
- Title
- monotonic deque
- Category
- C++
- Title
- file objects in c++
- Category
- C++
- Title
- how to load from files C++
- Category
- C++
- Title
- self in c++
- Category
- C++
- Title
- lopping over an array c++
- Category
- C++
- Title
- min and max heap in cpp
- Category
- C++
- Title
- lisy stl C++
- Category
- C++
- Title
- c++ how to make a negative float positive
- Category
- C++
- Title
- cpp create lambda with recursion
- Category
- C++
- Title
- pop_back
- Category
- C++
- Title
- print type cpp
- Category
- C++
- Title
- change int to string cpp
- Category
- C++
- Title
- recursion in cpp with reference
- Category
- C++
- Title
- inheritance protected in c++
- Category
- C++
- Title
- how to check type in c++
- Category
- C++
- Title
- length of array in cpp
- Category
- C++
- Title
- what is difference between ciel and floor
- Category
- C++
- Title
- c++ pointers
- Category
- C++
- Title
- c++ random
- Category
- C++
- Title
- C++ pointer arithmetic
- Category
- C++
- Title
- sqrt in c++
- Category
- C++
- Title
- how to initialize a vector in c++
- Category
- C++