-
Notifications
You must be signed in to change notification settings - Fork 1
Insea 99/week05 #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Insea 99/week05 #18
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,15 @@ | ||
| # pypy3 | ||
| # 시간(ms) : 132 | ||
| # 공간(KB) : 114336 | ||
|
|
||
| import sys | ||
| from collections import deque | ||
| input = sys.stdin.readline | ||
|
|
||
|
|
||
| q = deque() | ||
| for _ in range(int(input().strip())) : | ||
| k = int(input().strip()) | ||
| if k : q.append(k) # 0이 아니면 추가 | ||
| else : q.pop() # 0이면 최근 추가건 제거 | ||
| print(sum(q)) | ||
This file contains hidden or 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,31 @@ | ||
| # pypy3 | ||
| # 시간(ms) : 932 | ||
| # 공간(KB) : 162568 | ||
|
|
||
| import sys | ||
| from collections import deque | ||
| input = sys.stdin.readline | ||
|
|
||
| # 명령어 수행 할 함수 정의 | ||
| def push_queue(x): queue.append(int(x)) | ||
INSEA-99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def pop_queue(): return queue.popleft() if queue else -1 | ||
| def get_queue_size(): return len(queue) | ||
| def is_queue_empty(): return 1 if not queue else 0 | ||
| def queue_front(): return queue[0] if queue else -1 | ||
| def queue_back(): return queue[-1] if queue else -1 | ||
|
|
||
| # 명령어와 함수 맵핑 | ||
| commands = { | ||
| 'push': push_queue, | ||
| 'pop': pop_queue, | ||
| 'size': get_queue_size, | ||
| 'empty': is_queue_empty, | ||
| 'front': queue_front, | ||
| 'back': queue_back, | ||
| } | ||
|
|
||
| queue = deque() # queue 선언 | ||
| for _ in range(int(input().strip())) : | ||
| cmd = list(input().strip().split()) | ||
| result = commands[cmd[0]](*cmd[1:]) # 명령어 dict을 이용하여 함수 실행 | ||
| if result is not None : print(result) | ||
This file contains hidden or 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,14 @@ | ||
| # pypy3 | ||
| # 시간(ms) : 132 | ||
| # 공간(KB) : 121240 | ||
|
|
||
| import sys | ||
| from collections import deque | ||
| input = sys.stdin.readline | ||
|
|
||
| n = int(input().strip()) | ||
| q = deque(list(range(1, n+1))) # 1~n 리스트 생성 | ||
| while len(q) != 1 : # 1개 남을 때까지 수행 | ||
| q.popleft() | ||
| q.append(q.popleft()) | ||
| print(q[0]) |
This file contains hidden or 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,31 @@ | ||
| # pypy3 | ||
| # 시간(ms) : 476 | ||
| # 공간(KB) : 140540 | ||
|
|
||
| import sys | ||
| from collections import deque | ||
| input = sys.stdin.readline | ||
|
|
||
| # 명령어 수행 할 함수 정의 | ||
| def push_stack(x): stack.append(x) | ||
| def pop_stack(): return stack.pop() if stack else -1 | ||
| def get_stack_size(): return len(stack) | ||
| def is_stack_empty(): return 1 if not stack else 0 | ||
| def peek_stack(): return stack[-1] if stack else -1 | ||
|
|
||
| # 명령어와 함수 맵핑 | ||
| commands = { | ||
| 1: push_stack, | ||
| 2: pop_stack, | ||
| 3: get_stack_size, | ||
| 4: is_stack_empty, | ||
| 5: peek_stack | ||
| } | ||
|
|
||
| stack = deque() # stack 선언 | ||
| for _ in range(int(input().strip())) : | ||
| cmd = list(map(int, input().strip().split())) | ||
| result = commands[cmd[0]](*cmd[1:]) # 명령어 dict을 이용하여 함수 실행 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 호출부분이 증말 인상적입니다 깔끔 그 자체..!!!! |
||
| if result is not None : print(result) | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
조건을 바로 처리하니까 더 파이썬틱(?)하고 가독성이 좋습니다!