Advertisement
deushiro

Untitled

Jan 8th, 2020
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n;
  8.     cin >> n;
  9.     string s;
  10.     cin >> s;
  11.     int i = 0;
  12.     int j = n - 1;
  13.     int ans = 0;
  14.     int c = 0;
  15.     while(i < j){
  16.         ++ans;
  17.         if(c == 0){
  18.             while(i < n && s[i] == 'm'){
  19.                 ++i;
  20.             }
  21.             while(j > -1 && s[j] == 'c'){
  22.                 --j;
  23.             }
  24.             c = 1;
  25.         }
  26.         else{
  27.             while(i < n && s[i] == 'c'){
  28.                 ++i;
  29.             }
  30.             while(j > -1 && s[j] == 'm'){
  31.                 --j;
  32.             }
  33.             c = 0;
  34.         }
  35.     }
  36.     cout << ans - 1 << endl;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement