diff --git "a/robin/java/src/baekjoon/dataStructure/\354\212\244\355\203\235.java" "b/robin/java/src/baekjoon/dataStructure/\354\212\244\355\203\235.java" new file mode 100644 index 00000000..a473e41e --- /dev/null +++ "b/robin/java/src/baekjoon/dataStructure/\354\212\244\355\203\235.java" @@ -0,0 +1,44 @@ +package baekjoon.dataStructure; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Stack; + +public class 스택 { + + public static void main(String[] args) throws IOException { + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int n = Integer.parseInt(br.readLine()); + + Stack stack = new Stack(); + + for (int i = 0; i < n; i++) { + String[] input = br.readLine().split(" "); + + String instruction = input[0]; + + if (instruction.equals("push")) { + int num = Integer.parseInt(input[1]); + stack.push(num); + } + + if (instruction.equals("pop")) { + System.out.println(stack.isEmpty() ? -1 : stack.pop()); + } + + if (instruction.equals("size")) { + System.out.println(stack.size()); + } + + if (instruction.equals("empty")) { + System.out.println(stack.isEmpty() ? 1 : 0); + } + + if (instruction.equals("top")) { + System.out.println(stack.isEmpty() ? -1 : stack.peek()); + } + } + } +} diff --git "a/robin/java/src/baekjoon/math/\355\224\274\353\241\234\353\217\204.java" "b/robin/java/src/baekjoon/math/\355\224\274\353\241\234\353\217\204.java" new file mode 100644 index 00000000..bd95208e --- /dev/null +++ "b/robin/java/src/baekjoon/math/\355\224\274\353\241\234\353\217\204.java" @@ -0,0 +1,49 @@ +package baekjoon.math; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class 피로도 { + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + String[] input = br.readLine().split(" "); + // 피로도 + int a = Integer.parseInt(input[0]); + + // 일 처리 + int b = Integer.parseInt(input[1]); + + // 쉴 때 + int c = Integer.parseInt(input[2]); + + // limit + int m = Integer.parseInt(input[3]); + + int time = 24; + int tired = 0; + int process = 0; + + while (time > 0) { + + + if (tired + a <= m) { + tired += a; + process += b; + + } else { + tired -= c; + + if (tired < 0) { + tired = 0; + } + } + + time--; + } + + System.out.println(process); + } +} diff --git "a/robin/python/baekjoon/tree/\355\212\270\353\246\254\354\210\234\355\232\214.py" "b/robin/python/baekjoon/tree/\355\212\270\353\246\254\354\210\234\355\232\214.py" new file mode 100644 index 00000000..babbf47f --- /dev/null +++ "b/robin/python/baekjoon/tree/\355\212\270\353\246\254\354\210\234\355\232\214.py" @@ -0,0 +1,52 @@ +""" + +전위 순회(preorder): 루트 -> 왼쪽 자식 -> 오른쪽 자식 +중위 순회(inorder): 왼쪽 자식 -> 루트 -> 오른쪽 자식 +후위 순회(postorder): 왼쪽 자식 -> 오른쪽 자식 -> 루트 +""" + +import sys + +sys.setrecursionlimit(10 ** 6) + + +def preorder(node): + if node == '.': + return + + print(node, end="") # 루트 + preorder(tree[node][0]) # 왼쪽 자식 + preorder(tree[node][1]) # 오른쪽 자식 + + +def inorder(node): + if node == '.': + return + + inorder(tree[node][0]) # 왼쪽 자식 + print(node, end="") # 루트 + inorder(tree[node][1]) # 오른쪽 자식 + + +def postorder(node): + if node == '.': + return + + postorder(tree[node][0]) # 왼쪽 자식 + postorder(tree[node][1]) # 오른쪽 자식 + print(node, end="") # 루트 + + +if __name__ == '__main__': + n = int(input()) + tree = {} + + for _ in range(n): + root, left, right = input().split() + tree[root] = (left, right) + + preorder('A') + print() + inorder('A') + print() + postorder('A') diff --git "a/robin/python/programmers/level2/study21/\353\260\251\352\270\210\352\267\270\352\263\241.py" "b/robin/python/programmers/level2/study21/\353\260\251\352\270\210\352\267\270\352\263\241.py" new file mode 100644 index 00000000..82db1dab --- /dev/null +++ "b/robin/python/programmers/level2/study21/\353\260\251\352\270\210\352\267\270\352\263\241.py" @@ -0,0 +1,62 @@ +def change_minute(time): + ls = str(time).split(":") + h = int(ls[0]) + m = int(ls[1]) + + minute = h * 60 + minute += m + return minute + + +def change_melody(melody): + melody = melody.replace('C#', 'c') + melody = melody.replace('D#', 'd') + melody = melody.replace('F#', 'f') + melody = melody.replace('G#', 'g') + melody = melody.replace('A#', 'a') + return melody + + +def solution(m, musicinfos): + music = {} + + for input in musicinfos: + ls = input.split(",") + + # 시간 + time_1 = change_minute(ls[0]) + time_2 = change_minute(ls[1]) + time_diff = time_2 - time_1 + + # 노래제목 + title = ls[2] + + # 멜로디 + melody = change_melody(ls[3]) + + # 노래의 길이가 시간보다 더 긴 경우 + melody_time = time_diff - len(melody) + + # 시간만큼 재생된 음악 dictionary에 넣기 + # melody_time 이 음수나 0이 나오면 문자열 길이만큼의 노래만 재생하거나 더 적게 재생 + if melody_time <= 0: + music[melody[:time_diff]] = title + else: + mok, remain = divmod(time_diff, len(melody)) + string_melody = (melody * mok) + melody[:remain] + music[string_melody] = title + + sort_music = dict(sorted(music.items(), reverse=True, key=lambda item: len(item[0]))) + m = change_melody(m) + + for i in sort_music.keys(): + if m in i: + return sort_music.get(i) + + return "(None)" + + +if __name__ == '__main__': + m = "ABC" + musicinfos = ["12:00,12:14,HELLO,C#DEFGAB", "13:00,13:05,WORLD,ABCDEF"] + print(solution(m, musicinfos))