-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# for문 안의 num = int(input()) # 이 방법 시간초과=> 반복문으로 여러 줄 받을 때 input()은 시간초과 발생 | ||
|
||
import heapq, sys | ||
|
||
heap = [] | ||
n = int(input()) | ||
|
||
for i in range(n): | ||
num = int(sys.stdin.readline()) # 한 줄 입력 받아 정수형으로 형변환 | ||
if num == 0: # 0 입력되면 | ||
if heap: # 힙에 요소 있을 때 가장 큰 값 첫번째 루트 노드 삭제 | ||
print(heapq.heappop(heap)[1]) | ||
else:# 비어있을 때 0 출력 | ||
print(0) | ||
else: # 자연수 입력되면 | ||
heapq.heappush(heap, (-num, num)) # (우선순위, 값) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
num = int(input()) | ||
|
||
for i in range(num): | ||
N, M = map(int, input().split()) | ||
queue = list(map(int, input().strip().split())) | ||
queue = [(v, idx) for idx, v in enumerate(queue)] | ||
|
||
order = 0 | ||
|
||
while True: | ||
if max(queue)[0] == queue[0][0]: | ||
order += 1 | ||
if queue[0][1] == M: | ||
print(order) | ||
break | ||
else: | ||
queue.pop(0) | ||
else: | ||
queue.append(queue.pop(0)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
def solution(phone_book): | ||
answer = True | ||
hash = {} | ||
|
||
for i in phone_book: | ||
hash[i] = 0 | ||
|
||
for i in phone_book: | ||
print(i) | ||
temp = '' | ||
for j in i: | ||
temp += j | ||
if temp in hash and temp != i: | ||
answer = False | ||
return answer | ||
|
||
print(solution(["34", "3456", "789"])) |