알고리즘

[알고리즘] 백준 5586 - JOI와 IOI (C++)

blueberrysoda 2024. 10. 19. 23:35

[문제 링크] : https://www.acmicpc.net/problem/5586

#include <iostream>
#include <string>
using namespace std;

int J, I;
string S;

int main(){
    cin >> S;

    if(S.length() > 2){
        for(int i=0; i<S.length()-2; i++){
            if(S.substr(i, 3) == "JOI"){
                J++;
            }
            else if(S.substr(i, 3) == "IOI"){
                I++;
            }
        }
    }
    cout << J << "\n" << I << "\n";
    
    return 0;
}