diff --git a/README.md b/README.md index ed57901..916c43b 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ | 주차 | 카테고리 | 문제 번호 | 참여자 | | ------ | --------------------------------- | ---------------------------------------------------------------------------------- | -------------------------------- | | 1주차 | 수학 | [Week1](https://www.acmicpc.net/workbook/view/8997) | 최옐인😎 ❤️ 변영화😆 ❤️ 송인제😋 | -| 2주차 | 자료구조 (해시, 스택, 큐, 덱, 힙) | [Week2](https://www.acmicpc.net/workbook/view/8999) | 최옐인😊 | +| 2주차 | 자료구조 (해시, 스택, 큐, 덱, 힙) | [Week2](https://www.acmicpc.net/workbook/view/8999) | 최옐인😊 송인제😆 | | 3주차 | 재귀, 정렬 | [Week3](https://www.acmicpc.net/workbook/view/9000) | 최옐인😎 | | 4주차 | 다이나믹 프로그래밍 (DP) | [Week4](https://www.acmicpc.net/workbook/view/9001) | | | 5주차 | 그래프 - 기초 DFS와 BFS | [Week5](https://www.acmicpc.net/workbook/view/9003) | | diff --git a/week2/ssong/ssong_b11286.py b/week2/ssong/ssong_b11286.py new file mode 100644 index 0000000..99964d7 --- /dev/null +++ b/week2/ssong/ssong_b11286.py @@ -0,0 +1,17 @@ +# 절댓값 힙 + +import sys +import heapq + +N = int(sys.stdin.readline().rstrip()) +queue = [] + +for i in range(N): + x = int(sys.stdin.readline().rstrip()) + if x != 0: + heapq.heappush(queue, (abs(x), x)) + else: + if not queue: + print(0) + else: + print(heapq.heappop(queue)[1]) diff --git a/week2/ssong/ssong_b5430.py b/week2/ssong/ssong_b5430.py new file mode 100644 index 0000000..e5eac63 --- /dev/null +++ b/week2/ssong/ssong_b5430.py @@ -0,0 +1,32 @@ +# AC + +import sys +from collections import deque + +T = int(sys.stdin.readline().rstrip()) +for _ in range(T): + flag = 1; + p = sys.stdin.readline().rstrip() + n = int(sys.stdin.readline().rstrip()) + num_array = deque(sys.stdin.readline().strip()[1:-1].split(',')) + if n == 0: + num_array = deque() + for i in p: + if i == 'R': + flag *= (-1) + elif i == 'D': + if len(num_array) == 0: + print("error") + flag = 0 + break + else: + if flag == 1: + num_array.popleft() + elif flag == -1: + num_array.pop() + if flag == -1: + num_array.reverse() + print("[" + ",".join(num_array) + "]") + elif flag == 1: + print("[" + ",".join(num_array) + "]") + diff --git a/week3/ssong/ssong_b10870.py b/week3/ssong/ssong_b10870.py new file mode 100644 index 0000000..ce45c7d --- /dev/null +++ b/week3/ssong/ssong_b10870.py @@ -0,0 +1,15 @@ +# 피보나치 수 5 + +import sys + +n = int(sys.stdin.readline().rstrip()) + +def fibo(n): + if n == 0: + return 0 + elif n == 1: + return 1 + else: + return (fibo(n - 1) + fibo(n - 2)) + +print(fibo(n)) \ No newline at end of file diff --git a/week3/ssong/ssong_b11729.py b/week3/ssong/ssong_b11729.py new file mode 100644 index 0000000..4e04885 --- /dev/null +++ b/week3/ssong/ssong_b11729.py @@ -0,0 +1,20 @@ +# 하노이 탑 이동 순서 + +import sys +# 원판의 개수 N +N = int(sys.stdin.readline().rstrip()) + +# N 홀수일 때 3에 먼저 올려야함 +# N 짝수일 때 2에 먼저 올려야함 + +def hanoi(N, a, b, c): + if N == 1: + print(a, c, sep = " ") + else: + hanoi(N - 1, a, c, b) + hanoi(1, a, b, c) + hanoi(N - 1, b, a, c) + +print(2**N - 1) +if(N <= 20): + hanoi(N, 1, 2, 3) diff --git a/week3/ssong/ssong_b17478.py b/week3/ssong/ssong_b17478.py new file mode 100644 index 0000000..2dbea70 --- /dev/null +++ b/week3/ssong/ssong_b17478.py @@ -0,0 +1,37 @@ +# 재귀함수가 뭔가요? + +import sys + +N = int(sys.stdin.readline().rstrip()) + +print("어느 한 컴퓨터공학과 학생이 유명한 교수님을 찾아가 물었다.") + +def last_print(index): + print_dot(index) + print("\"재귀함수가 뭔가요?\"") + print_dot(index) + print("\"재귀함수는 자기 자신을 호출하는 함수라네\"") + print_dot(index) + print("라고 답변하였지.") + +def print_dot(index): + for _ in range(index): + print("____", end='') + +def recursive(N, index): + if index >= N: + last_print(index) + else: + print_dot(index) + print("\"재귀함수가 뭔가요?\"") + print_dot(index) + print("\"잘 들어보게. 옛날옛날 한 산 꼭대기에 이세상 모든 지식을 통달한 선인이 있었어.") + print_dot(index) + print("마을 사람들은 모두 그 선인에게 수많은 질문을 했고, 모두 지혜롭게 대답해 주었지.") + print_dot(index) + print("그의 답은 대부분 옳았다고 하네. 그런데 어느 날, 그 선인에게 한 선비가 찾아와서 물었어.\"") + recursive(N, index + 1) + print_dot(index) + print("라고 답변하였지.") + +recursive(N, 0); diff --git a/week3/ssong/ssong_b1914.py b/week3/ssong/ssong_b1914.py new file mode 100644 index 0000000..1de2c98 --- /dev/null +++ b/week3/ssong/ssong_b1914.py @@ -0,0 +1,20 @@ +# 하노이 탑 + +import sys +# 원판의 개수 N +N = int(sys.stdin.readline().rstrip()) + +# N 홀수일 때 3에 먼저 올려야함 +# N 짝수일 때 2에 먼저 올려야함 + +def hanoi(N, a, b, c): + if N == 1: + print(a, c, sep = " ") + else: + hanoi(N - 1, a, c, b) + hanoi(1, a, b, c) + hanoi(N - 1, b, a, c) + +print(2**N - 1) +if(N <= 20): + hanoi(N, 1, 2, 3)