Advertisement
Misha_

Костыли на А08 из Just for It

Sep 23rd, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4. typedef unsigned int ui;
  5.  
  6. int main() {
  7.     char s[1001] = {}, previous;
  8.     bool flag = false;
  9.     cin.getline(s,1000);
  10.     ui SZ = strlen(s), count = 0;
  11.     for (ui i = 0; i < SZ; ++i) {
  12.         if (SZ == 2 && s[0] == s[1]) {
  13.             cout << s[0] << 2;
  14.             break;
  15.         }
  16.         if (i == 0) {
  17.             if (s[0] != s[1])
  18.                 cout << s[0];
  19.             previous = s[i];
  20.             count = 1;
  21.             flag = true;
  22.             continue;
  23.         }
  24.         if (s[i] == previous) {
  25.             ++count;
  26.         }
  27.         if (i == SZ-1 && SZ > 2) {
  28.             if (s[SZ-1] != s[SZ-2]) {
  29.                 cout << previous;
  30.                     if (count != 1)
  31.                         cout << count;
  32.                     count = 1;
  33.                     cout << s[i];
  34.                     if (count != 1)
  35.                         cout << count;
  36.                     break;
  37.             }
  38.             cout << s[i];
  39.             if (count != 1)
  40.                 cout << count;
  41.             break;
  42.         }
  43.         if (i == SZ-1 && SZ == 2) {
  44.             cout << s[i];
  45.  
  46.         }
  47.         if (s[i] != previous && !flag) {
  48.             cout << previous;
  49.             if (count != 1)
  50.                 cout << count;
  51.             count = 1;
  52.         }
  53.         flag = false;
  54.         previous = s[i];
  55.     }
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement