Advertisement
vencinachev

Kontrolno1-Zad1

May 28th, 2021
1,128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. void stringDecompress(char* result, const char* str)
  7. {
  8.     char numstr[] = "0";
  9.     strcpy(result, "");
  10.     int i = 0;
  11.     while (*(str + i))
  12.     {
  13.         if (isdigit(str[i]))
  14.         {
  15.             strncat(numstr, &str[i], 1);
  16.         }
  17.         else
  18.         {
  19.             int cnt = atoi(numstr);
  20.             for (int j = 0; j < cnt; j++)
  21.             {
  22.                 strncat(result, &str[i], 1);
  23.             }
  24.             strcpy(numstr, "0");
  25.         }
  26.         i++;
  27.     }
  28. }
  29.  
  30. int main()
  31. {
  32.     char *str;
  33.     stringDecompress(str, "3A2B4C");
  34.     int i = 0;
  35.     while (*(str + i))
  36.     {
  37.         cout << str[i];
  38.         i++;
  39.     }
  40.     cout << endl;
  41.  
  42.  
  43.     stringDecompress(str, "12W1B12W3B24W1B14W");
  44.     i = 0;
  45.     while (*(str + i))
  46.     {
  47.         cout << str[i];
  48.         i++;
  49.     }
  50.     cout << endl;
  51.     return 0;
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement