vencinachev

Zad1

Apr 19th, 2021
534
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. void stringCompress(char* result, const char *str)
  7. {
  8.     strcpy(result, "");
  9.     char numbuff[10];
  10.     char buff1[10];
  11.     int i = 0;
  12.     char current;
  13.     int cnt = 0;
  14.     while(*(str + i))
  15.     {
  16.         char current = str[i];
  17.         do
  18.         {
  19.             i++;
  20.             cnt++;
  21.         }
  22.         while (str[i] == current);
  23.         itoa(cnt, numbuff, 10);
  24.         cnt = 0;
  25.         sprintf(buff1, "%s%c", numbuff, current);
  26.         strcat(result, buff1);
  27.     }
  28. }
  29.  
  30. int main()
  31. {
  32.     char str[200];
  33.     stringCompress(str, "AAABBCCCC");
  34.     cout << str << endl;
  35.     stringCompress(str, "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWW");
  36.     cout << str << endl;
  37.     return 0;
  38. }
  39.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×