Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- web
- Reversing
- 누적 합
- 시뮬레이션
- 재귀
- thymeleaf
- Spring
- 분할 정복
- BFS
- 최단 경로
- 구현
- dynamic debugging
- GCP
- CVE
- c++
- OS
- 이분 탐색
- 우선순위 큐
- 백트래킹
- JPA
- 그리디
- java
- 데이크스트라
- 문자열
- 위상 정렬
- error
- 맵
- dfs
- DP
- 스택
Archives
- Today
- Total
hades
[Baekjoon] 5525번: IOIOI 본문
🥅 문제
https://www.acmicpc.net/problem/5525
🔍 설계
IOIOIOIOI에서 n=1이라면 4, n=2라면 3, n=3이라면 2, n=4라면 1이 된다.
IOI의 개수가 4이므로, 결과값은 IOI 개수 + 1 - n이다.
👊 풀이
#include <iostream>
#include <string>
#include <deque>
using namespace std;
int n, m;
string s;
int result = 0;
int main(void)
{
cin >> n >> m >> s;
for (int i = 0; i < m; i++) {
int count = 0;
if (s[i] == 'I') {
while (true) {
if (s[i + 1] == 'O' && s[i + 2] == 'I') {
count += 1;
i = i + 2;
}
else {
break;
}
}
}
if (count+1-n>0){
result += count+1-n;
}
}
cout << result << "\n";
return 0;
}
📝 메모
IOI의 개수보다 n이 큰 경우, 음수가 되기 때문에 조건을 추가해야 한다.
'👊 PS > Algorithm' 카테고리의 다른 글
[Baekjoon] 7662번: 이중 우선순위 큐 (0) | 2024.07.17 |
---|---|
[Baekjoon] 7569번: 토마토 (0) | 2024.07.16 |
[Baekjoon] 5430번: AC (0) | 2024.07.15 |
[Baekjoon] 2667번: 단지번호붙이기 (0) | 2024.07.13 |
[Baekjoon] 2630번: 색종이 만들기 (0) | 2024.07.11 |