Skip to content

Commit

Permalink
2024-09-24 IOIOI
Browse files Browse the repository at this point in the history
  • Loading branch information
janghw0126 committed Sep 24, 2024
1 parent e244b99 commit e6d1a40
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions janghw0126/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@
| 9차시 | 2024.8.25 | BFS | <a href= "https://www.acmicpc.net/problem/1697">숨바꼭질</a> |[#149](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/149) |
| 10차시 | 2024.9.9 | 위상정렬 | <a href= "https://www.acmicpc.net/problem/2252">줄 세우기</a> |[#158](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/158) |
| 11차시 | 2024.9.17 | 우선순위 큐 | <a href= "https://www.acmicpc.net/problem/7662">이중 우선순위 큐</a> |[#160](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/160) |
| 12차시 | 2024.9.24 | 투 포인터 | <a href= "https://www.acmicpc.net/problem/5525">IOIOI</a> |[#163](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/163) |
---
32 changes: 32 additions & 0 deletions janghw0126/투 포인터/IOIOI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import sys
input = sys.stdin.readline

n = int(input())
m = int(input())
sequence = input().rstrip()

# 투 포인터 알고리즘을 위해서 좌우 포인터 선언
start, current = 0, 0
# 'IOI' 패턴을 찾은 횟수 선언
pattern_count = 0

# 문자열 범위 내에서 반복
while current < m:
# 현재 위치에서 'IOI' 패턴이 발견된 경우
if sequence[current:current + 3] == 'IOI':
# 패턴을 찾으면 포인터를 두 칸씩 이동
current += 2
# 패턴의 길이가 'N'에 맞는 경우
if current - start == 2 * n:
# 패턴 카운트 증가
pattern_count += 1
# 패턴을 완성했으니 시작 포인터도 두 칸 이동
start += 2
else:
# 패턴이 맞지 않으면 한 칸씩 이동
current += 1
# 시작 포인터를 현재 포인터 위치로 재설정
start = current

# 패턴 횟수 출력
print(pattern_count)

0 comments on commit e6d1a40

Please sign in to comment.