https://www.acmicpc.net/problem/5525
5525번: IOIOI
N+1개의 I와 N개의 O로 이루어져 있으면, I와 O이 교대로 나오는 문자열을 PN이라고 한다. P1 IOI P2 IOIOI P3 IOIOIOI PN IOIOI...OI (O가 N개) I와 O로만 이루어진 문자열 S와 정수 N이 주어졌을 때, S안에 PN이 몇
www.acmicpc.net
#include <iostream>
#include <string>
using namespace std;
int main() {
int N, M; cin >> N >> M;
string str; cin >> str;
int answer = 0;
for (int i = 1; i < str.size() - 1; i++) {
int count = 0;
while (i<str.size()-1 && str[i] == 'O' && str[i - 1] == 'I' && str[i + 1] == 'I') {
count++;
i += 2;
}
if (count >= N) {
answer += count - N + 1;
}
}
cout << answer << endl;
return 0;
}
'전공공부 > 코딩테스트' 카테고리의 다른 글
(C++) 프로그래머스 "보행자 천국" (0) | 2022.06.10 |
---|---|
(c++) 백준 "1992) 쿼드 트리" (0) | 2022.06.09 |
(c++) 프로그래머스 "섬 연결하기" (0) | 2022.06.08 |
(c++) 백준 "1780) 종이의 개수" (0) | 2022.06.07 |
(c++) 백준 "1541) 잃어버린 괄호" (0) | 2022.06.07 |