Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #pragma GCC optimize ("O3")
  4.  
  5. int main()
  6. {
  7.     std::cout.sync_with_stdio(false);
  8.     std::cin.sync_with_stdio(false);
  9.     std::cin.tie(nullptr);
  10.  
  11.     std::string input;
  12.     std::cin >> input;
  13.  
  14.     char current_char = input[0];
  15.     int count_char = 0;
  16.  
  17.     for (char ch : input)
  18.     {
  19.         if (current_char != ch)
  20.         {
  21.             if (count_char > 2)
  22.             {
  23.                 std::cout << count_char << current_char;
  24.             }
  25.             else
  26.             {
  27.                 for (int i = 0; i < count_char; ++i)
  28.                 {
  29.                     std::cout << current_char;
  30.                 }
  31.             }
  32.             current_char = ch;
  33.             count_char = 1;
  34.         }
  35.         else
  36.         {
  37.             count_char++;
  38.         }
  39.     }
  40.  
  41.     if (count_char > 2)
  42.     {
  43.         std::cout << count_char << current_char;
  44.     }
  45.     else
  46.     {
  47.         for (int i = 0; i < count_char; ++i)
  48.         {
  49.             std::cout << current_char;
  50.         }
  51.     }
  52.  
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement