Skip to content

Commit daf035a

Browse files
committed
[Silver I] Title: IOIOI, Time: 140 ms, Memory: 14420 KB, Score: 50 point -BaekjoonHub
1 parent e974e74 commit daf035a

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
static int N,M;
6+
static String S;
7+
public static void main(String[] args) throws IOException {
8+
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
11+
N= Integer.parseInt(br.readLine());
12+
M = Integer.parseInt(br.readLine());
13+
14+
S = br.readLine();
15+
16+
int answer = 0;
17+
18+
for(int i =0; i<S.length(); i++) {
19+
if(S.charAt(i) == 'I') {
20+
if(check(i)) {
21+
answer+=1;
22+
}
23+
}
24+
}
25+
26+
System.out.println(answer);
27+
}
28+
static boolean check(int startIndex) {
29+
int oCount = 0;
30+
31+
int maxLength = N*2 +1;
32+
boolean checking = true;
33+
for(int i = startIndex; i< startIndex+ maxLength; i++) {
34+
if(i > S.length()-1) {
35+
checking = false;
36+
break;
37+
}
38+
if(i != startIndex &&i > 0 && S.charAt(i) == S.charAt(i-1)) {
39+
checking = false;
40+
break;
41+
}
42+
if(S.charAt(i) == 'O') {
43+
oCount+=1;
44+
}
45+
}
46+
47+
if(oCount == N && checking) {
48+
return true;
49+
}
50+
return false;
51+
}
52+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# [Silver I] IOIOI - 5525
2+
3+
[문제 링크](https://www.acmicpc.net/problem/5525)
4+
5+
### 성능 요약
6+
7+
메모리: 14420 KB, 시간: 140 ms
8+
9+
### 분류
10+
11+
문자열
12+
13+
### 제출 일자
14+
15+
2025년 1월 7일 14:18:00
16+
17+
### 문제 설명
18+
19+
<p>N+1개의 <code>I</code>와 N개의 <code>O</code>로 이루어져 있으면, <code>I</code>와 <code>O</code>이 교대로 나오는 문자열을 P<sub>N</sub>이라고 한다.</p>
20+
21+
<ul>
22+
<li>P<sub>1</sub> <code>IOI</code></li>
23+
<li>P<sub>2</sub> <code>IOIOI</code></li>
24+
<li>P<sub>3</sub> <code>IOIOIOI</code></li>
25+
<li>P<sub>N</sub> <code>IOIOI...OI</code> (<code>O</code>가 N개)</li>
26+
</ul>
27+
28+
<p><code>I</code>와 <code>O</code>로만 이루어진 문자열 S와 정수 N이 주어졌을 때, S안에 P<sub>N</sub>이 몇 군데 포함되어 있는지 구하는 프로그램을 작성하시오.</p>
29+
30+
### 입력
31+
32+
<p>첫째 줄에 N이 주어진다. 둘째 줄에는 S의 길이 M이 주어지며, 셋째 줄에 S가 주어진다.</p>
33+
34+
### 출력
35+
36+
<p>S에 P<sub>N</sub>이 몇 군데 포함되어 있는지 출력한다.</p>
37+

0 commit comments

Comments
 (0)