Advertisement
pochti_da

Untitled

May 19th, 2021
885
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. void out(int num, char last) {
  4.     if (num > 4 || last == '#') {
  5.         std::cout << "#" << last << std::hex << num << "#";
  6.     } else {
  7.         while(num--) {
  8.             std::cout << last;
  9.         }
  10.     }
  11. }
  12.  
  13. int main()
  14. {
  15.     char last;
  16.     char cur;
  17.     int num = 1;
  18.     if (!std::cin.get(last)) {
  19.         return 0;
  20.     }
  21.     while (std::cin.get(cur)) {
  22.         if (cur == last) {
  23.             ++num;
  24.         } else {
  25.             out(num, last);
  26.             num = 1;
  27.         }
  28.         last = cur;
  29.     }
  30.     out(num, last);
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement