kolioi

Decompression (w/o sstream) C++

Dec 27th, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. int main()
  5. {
  6.     using namespace std;
  7.  
  8.     string szInput;
  9.     getline(cin, szInput);
  10.  
  11.     for (int i = 0; i < szInput.length(); i++)
  12.     {
  13.         char ch = szInput[i];
  14.         int nCurNum = 0;
  15.         while (ch >= '0' && ch <= '9')
  16.         {
  17.             if (!nCurNum)
  18.                 nCurNum = ch - '0';
  19.             else
  20.                 nCurNum = 10 * nCurNum + ch - '0';
  21.             ch = szInput[++i];
  22.         }
  23.  
  24.         if (!nCurNum)
  25.             nCurNum = 1;
  26.  
  27.         cout << string(nCurNum, ch);
  28.     }
  29.  
  30.     cout << endl;
  31.  
  32.     return 0;
  33. }
Add Comment
Please, Sign In to add comment