Skip to content

Commit 8b438ec

Browse files
authored
Merge pull request #91 from zaqquum/main
[11월 3째주_ Week01] 스터디 자료 공유
2 parents 8f2cf3f + e261b42 commit 8b438ec

File tree

5 files changed

+93
-0
lines changed

5 files changed

+93
-0
lines changed

Hongjoo/백준/문자열교환.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
https://www.acmicpc.net/problem/1522
3+
"""
4+
5+
words= input()
6+
window_size = words.count("a") # 1. a의 개수 = sliding window 크기
7+
result = 999999999
8+
9+
# 원형 문자열
10+
words += words[0:window_size-1]
11+
# 2. 최대한 a 가 연속해 있는 idx 범위 찾기
12+
for start in range(len(words) - (window_size-1)):
13+
result = min(result, words[start: start+ window_size].count("b"))
14+
15+
print(result)

Hongjoo/백준/부분합.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
https://www.acmicpc.net/problem/1806
3+
"""
4+
import sys
5+
N ,S = map(int, sys.stdin.readline().split())
6+
arr = list(map(int, input().split()))
7+
8+
start , end = 0, 0
9+
min_length = 100000
10+
partial_sum = arr[0]
11+
while start <= end :
12+
if partial_sum >= S : # S보다 큰 부분합인 경우
13+
min_length = min(min_length , end - start +1 ) # 최소 길이 업데이트 확인
14+
partial_sum -= arr[start] # start +1 이동
15+
start += 1
16+
else : #partial_sum < S :
17+
end += 1
18+
if end < N :
19+
partial_sum += arr[end]
20+
else : # 수열 끝 -> 조건 충족 x
21+
break
22+
23+
24+
if min_length == 100000 :
25+
print(0)
26+
else :
27+
print(min_length)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
[백준#1522.문자열 교환.py]
3+
https://www.acmicpc.net/problem/1522
4+
5+
# 문자열 , 투 포인터
6+
7+
"""
8+
# 1. a의 개수 = sliding window 크기
9+
words= input()
10+
window_size = words.count("a")
11+
result = 999999999
12+
13+
# 원형 문자열
14+
words += words[0:window_size-1]
15+
# 슬라이싱 된 문자열 속 b의 개수 최소값
16+
for start in range(len(words) - (window_size-1)):
17+
result = min(result, words[start: start+ window_size].count("b"))
18+
19+
print(result)
Binary file not shown.

발제/W01/Test/1806_부분합.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'''
2+
[백준#1806.부분합]
3+
https://www.acmicpc.net/problem/1806
4+
5+
참조:
6+
https://aia1235.tistory.com/46
7+
'''
8+
9+
import sys
10+
N ,S = map(int, sys.stdin.readline().split())
11+
arr = list(map(int, input().split()))
12+
13+
start , end = 0, 0
14+
min_length = 100000
15+
partial_sum = arr[0]
16+
while start <= end :
17+
if partial_sum >= S : # S보다 큰 부분합인 경우
18+
min_length = min(min_length , end - start +1 ) # 최소 길이 업데이트 확인
19+
partial_sum -= arr[start] # start +1 이동
20+
start += 1
21+
else : #partial_sum < S :
22+
end += 1
23+
if end < N :
24+
partial_sum += arr[end]
25+
else : #반복문 끝
26+
break
27+
28+
29+
if min_length == 100000 : # 수열 끝 -> 조건 충족 x
30+
print(0)
31+
else :
32+
print(min_length)

0 commit comments

Comments
 (0)