5525번: IOIOI
https://www.acmicpc.net/problem/5525
# 코드
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);
}
}
'코딩테스트 > 자바 문제풀이' 카테고리의 다른 글
[CLASS 3: 최단경로] 백준 11403 경로 찾기 (0) | 2024.11.19 |
---|---|
[CLASS 3: 브루트포스] 백준 6064 카잉 달력 (1) | 2024.11.18 |
[CLASS 3: BFS] 백준 2667 단지번호붙이기 (0) | 2024.11.16 |
[CLASS 3: BFS] 백준 2178 미로 탐색 (0) | 2024.11.15 |
[CLASS 3: 그리디] 백준 1931 회의실 배정 (1) | 2024.11.14 |