Advertisement
OIQ

spbgu1

OIQ
Jan 8th, 2020
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.  
  10.     int n;
  11.     cin >> n;
  12.  
  13.     string s;
  14.     cin >> s;
  15.  
  16.     int f1 = 0, f2 = 0;
  17.  
  18.     int i = 0, j = s.size() - 1;
  19.  
  20.     int r = 0;
  21.     int ans = 0;
  22.  
  23.     while (i <= j) {
  24.         if (r == 0) {
  25.             if (s[i] == 'm') i++;
  26.             else
  27.                 f1 = 1;
  28.             if (s[j] == 'c') j--;
  29.             else
  30.                 f2 = 1;
  31.             if (f1 == 1 && f2 == 1) {
  32.                 r = 1;
  33.                 f1 = 0;
  34.                 f2 = 0;
  35.                 ans++;
  36.             }
  37.  
  38.         }
  39.         else {
  40.             if (s[i] == 'c') i++;
  41.             else
  42.                 f1 = 1;
  43.             if (s[j] == 'm') j--;
  44.             else
  45.                 f2 = 1;
  46.             if (f1 == 1 && f2 == 1) {
  47.                 r = 0;
  48.                 f1 = 0;
  49.                 f2 = 0;
  50.                 ans++;
  51.             }
  52.         }
  53.     }
  54.     cout << ans;
  55.  
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement