kolioi

Decompression (w/ sstream) C++

Dec 27th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3.  
  4. int main()
  5. {
  6.     using namespace std;
  7.  
  8.     string text;
  9.     getline(cin, text);
  10.  
  11.     ostringstream out;
  12.     int num = 0;
  13.     char ch;
  14.     while (!text.empty())
  15.     {
  16.         istringstream iss(text);
  17.         iss >> num;
  18.         iss.clear();
  19.         iss.get(ch);
  20.         if (num)
  21.         {
  22.             while (num--)
  23.                 out << ch;
  24.             num = 0;
  25.         }
  26.         else
  27.             out << ch;
  28.         getline(iss, text);
  29.     }
  30.  
  31.     cout << out.str() << endl;
  32.  
  33.     return 0;
  34. }
Add Comment
Please, Sign In to add comment