Advertisement
intsashka

mz07-1

Apr 27th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. int
  5. main(void)
  6. {
  7.     std::cout.unsetf(std::ios::dec);
  8.     std::cout.setf(std::ios::hex);
  9.  
  10.     constexpr int MAX_CHAR = 4;
  11.  
  12.     int ch = std::cin.get();
  13.  
  14.     while (ch != EOF) {
  15.         int old = ch;
  16.         int count = 1;
  17.         while (old == (ch = std::cin.get())) {
  18.             ++count;
  19.         }
  20.  
  21.         if (old == '#' or count > MAX_CHAR) {
  22.             std::cout << '#' << char(old) << count << '#';
  23.         } else {
  24.             while (count-- > 0) {
  25.                 std::cout << char(old);
  26.             }
  27.         }
  28.     }
  29.  
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement