본문 바로가기
알고리즘/Class 3

백준 BOJ 5525번 - IOIOI

by edvedv 2022. 9. 5.


코드

import java.util.*;
 
public class Main {
   public static void main(String[] args) {
      Scanner in = new Scanner(System.in);
      int N = in.nextInt();
      int M = in.nextInt();
      char S[] = in.next().toCharArray();

      int answer = 0, count = 0;
      for(int i = 1; i < M - 1; i++) {
         if(S[i] == 'O' && S[i + 1] == 'I'){
            count++;
            if(count == N) {
               if(S[i - (N * 2 - 1)] == 'I')
                  answer++;
               count--;
            }
            i++;
         }
         else 
            count = 0; 
      }
      System.out.println(answer);
      in.close();
   }
}

'알고리즘 > Class 3' 카테고리의 다른 글

백준 BOJ 6064번 - 카잉 달력  (0) 2022.09.23
백준 BOJ 5430번 - AC  (0) 2022.09.04
백준 BOJ 2667번 - 단지번호붙이기  (0) 2022.08.31
백준 BOJ 2630번 - 색종이 만들기  (0) 2022.08.31
백준 BOJ 2606번 - 바이러스  (0) 2022.08.30

댓글