Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- void stringCompress(char* result, const char *str)
- {
- strcpy(result, "");
- char numbuff[10];
- char buff1[10];
- int i = 0;
- char current;
- int cnt = 0;
- while(*(str + i))
- {
- char current = str[i];
- do
- {
- i++;
- cnt++;
- }
- while (str[i] == current);
- itoa(cnt, numbuff, 10);
- cnt = 0;
- sprintf(buff1, "%s%c", numbuff, current);
- strcat(result, buff1);
- }
- }
- int main()
- {
- char str[200];
- stringCompress(str, "AAABBCCCC");
- cout << str << endl;
- stringCompress(str, "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWW");
- cout << str << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement