Skip to content

Commit

Permalink
6/24 문자열 뒤집기
Browse files Browse the repository at this point in the history
최은기 authored and 최은기 committed Jun 23, 2021
1 parent 4003699 commit b820b69
Showing 10 changed files with 84 additions and 11 deletions.
8 changes: 8 additions & 0 deletions choieungi/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions choieungi/.idea/choieungi.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions choieungi/.idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions choieungi/.idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions choieungi/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions choieungi/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions choieungi/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions choieungi/NewThisIsCT/11_3 문자열 뒤집기 - 1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
s = list(map(int, input())) # change string to int list

def check_str(s, find):
idx = 0
cnt = 0
flag = False
while True:
if idx == len(s): return cnt

if s[idx] is not find :
flag = False
idx += 1

elif s[idx] == find and not flag:
idx += 1
flag = True
cnt += 1

elif s[idx] == find and flag:
idx += 1

print(min(check_str(s, 0), check_str(s, 1)))
7 changes: 7 additions & 0 deletions choieungi/NewThisIsCT/11_3 문자열 뒤집기 - 2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def solution(s, basis):
block = s.split(str(basis)) # change basis to '' in string. ex) "001100" -> ['','','11','','']
return len(block) - block.count('') # count the sequence number


s = input()
print(min(solution(s, 0),solution(s,1)))
16 changes: 5 additions & 11 deletions choieungi/main.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import heapq
def solution(s, basis):
block = s.split(str(basis)) # change basis to '' in string. ex) "001100" -> ['','','11','','']
return len(block) - block.count('') # count the sequence number

def solution(scoville, K):
answer = 0
heapq.heapify(scoville)
while scoville[0]<K:
if len(scoville)>=2:
heapq.heappush(scoville, (heapq.heappop(scoville))+heapq.heappop(scoville)*2)
answer+=1
else:
return -1

return answer
s = input()
print(min(solution(s, 0),solution(s,1)))

0 comments on commit b820b69

Please sign in to comment.