Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <string>
- using namespace std;
- int main() {
- int n;
- cin >> n;
- string s;
- cin >> s;
- int f1 = 0, f2 = 0;
- int i = 0, j = s.size() - 1;
- int r = 0;
- int ans = 0;
- while (i <= j) {
- if (r == 0) {
- if (s[i] == 'm') i++;
- else
- f1 = 1;
- if (s[j] == 'c') j--;
- else
- f2 = 1;
- if (f1 == 1 && f2 == 1) {
- r = 1;
- f1 = 0;
- f2 = 0;
- ans++;
- }
- }
- else {
- if (s[i] == 'c') i++;
- else
- f1 = 1;
- if (s[j] == 'm') j--;
- else
- f2 = 1;
- if (f1 == 1 && f2 == 1) {
- r = 0;
- f1 = 0;
- f2 = 0;
- ans++;
- }
- }
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement