fork(1) download
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4. string S;
  5. int main() {
  6. cin >> S;
  7. int cnt = 0;
  8. for (int i = 0; i < S.size(); i++) {
  9. if (S[i] == 'I' && cnt % 2 == 0) {
  10. cnt++;
  11. }
  12. else if (S[i] == 'O' && cnt % 2 == 1) {
  13. cnt++;
  14. }
  15. }
  16. if (cnt % 2 == 0 && cnt >= 1) { cnt--; }
  17. cout << cnt << endl;
  18. return 0;
  19. }
Success #stdin #stdout 0s 3460KB
stdin
IOOIIOIOIIOI
stdout
9