일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- Sequential Search
- Counting cells in a blob
- data_structure
- 피보나치 수
- 10953
- adjacentElementsProduct
- Daily Commit
- cpp
- flask
- C++
- til
- codesignal
- 파이썬머신러닝완벽가이드
- 백준
- Numpy
- codesingal
- Python
- All Longest Strings
- 수 정렬하기
- 2750
- shapeArea
- 파이썬 포렌식
- 2015 봄학기 알고리즘
- recursion
- collections.deque
- markdown
- baekjun
- matrixElementsSum
- centuryFromYear
- almostIncreasingSequence
Archives
- Today
- Total
Introfor
[백준] 9093번 stack 본문
기본적인 자료구조인 스택 관련 문제로 백준 사이트에 있는 문제를 풀어보았다.
__author__ = 'hanayong'
stack = []
def push(word):
global stack
for _ in range(len(word)):
stack.append(word.pop())
def pop():
global stack
if stack in []:
return
else:
return stack.pop()
def reserve_words():
global stack
word_list = []
for _ in range(len(stack)):
word_list.append(pop()[::-1])
print(' '.join(word_list))
if __name__ == '__main__':
n = int(input())
for _ in range(n):
factors = input().split()
push(factors)
reserve_words()
위 소스코드는 스택 형태로 구현했다. 선입후출 구조를 구현해보기 위해 전역변수 stack을 만들고 push(), pop()을 구현했다.
위 방법이 아닌 더 쉬운 방법으로 구현이 가능하다.
__author__ = 'hanayong'
n = int(input())
for _ in range(n):
strings = list(map(list, input().split()))
for i in strings:
print(''.join(i[::-1]), end=' ')
각각의 단어를 알파벳으로 나누고, 나눠진 알파벳을 뒤집어서 재조합하는 방식으로 문제를 풀었다.
'Programming_prob > BaekJoon' 카테고리의 다른 글
[백준] 1406번 에디터 (0) | 2020.09.11 |
---|---|
[백준]1872번 스택 수열 (0) | 2020.09.11 |
[백준] 10953번 / A+B - 6 (0) | 2020.07.03 |
[백준] 10870번 / 피보나치 수 5 (0) | 2020.07.01 |
[백준] 10872번 / 팩토리얼 (0) | 2020.07.01 |
Comments