백준 5525번(Java)

박은지·2025년 5월 23일
0

백준

목록 보기
74/89
post-thumbnail

import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int m = Integer.parseInt(br.readLine());
        String str = br.readLine();
        int cnt=0, ans=0;
        
        for(int i=1; i<m-1;){
            if(str.charAt(i)=='O' && str.charAt(i+1)=='I'){
                cnt++;
                if(cnt == n){
                    if(str.charAt(i-(cnt*2-1))=='I')
                        ans ++;
                    cnt--;
                }
                i+=2;
            }
            else {
                cnt=0;
                i++;
            }
        }
        System.out.println(ans);
    }
}
profile
백엔드 개발자가 되고싶은 eunzi😊

0개의 댓글