본문 바로가기
728x90

Programming/Python46

[백준] 10773 | 제로 2년 전 코드from collections import dequeimport sysinput = sys.stdin.readlinek = int(input())stack = deque([])for _ in range(k): tmp = int(input()) if tmp != 0: stack.append(tmp) else: stack.pop()print(sum(stack))(good) 대체적으로 괜찮음!개선 코드from collections import dequeimport sysinput = sys.stdin.readlineif __name__ == "__main__": k = int(input()) stack = deque([]) for _ in .. 2024. 12. 11.
[백준] 1920 | 수 찾기 import sysinput = sys.stdin.readlinedef binary_search(arr, target, start, end): while start target: end = mid - 1 else: start = mid + 1 return 0if __name__ == "__main__": n = int(input()) n_list = sorted(list(map(int, input().split()))) m = int(input()) m_list = list(map(int, input().split())) for m_item in m_list: if m_item > n_list[-1] .. 2024. 12. 11.
[백준] 10828 | 스택 2년 전 코드import sysinput = sys.stdin.readlineN = int(input())s = []def command(com_list, stack): # push if len(com_list) > 1: if com_list[0] == 'push': stack.append(int(com_list[1])) # top, size, empty, pop else: if com_list[0] == 'pop': if stack: print(stack.pop()) else: print(-1) elif com_list[0] == '.. 2024. 12. 10.
[백준] 9012 | 괄호 4년 전 코드T = int(input())for i in range(T): string = input() num1 = 0 num2 = 0 for j in string: if num2 > num1: break else: if j == "(": num1 += 1 elif j == ")": num2 += 1 if num1 == num2: print("YES") else: print("NO")(good) 단순하게 해결(bad) 신뢰성 떨어지는 코드 개선 코드from collections import dequeimport.. 2024. 12. 10.
[백준] 10845 | 큐 처음부터 다시 공부하는 알고리즘 / 자료구조....  2년 전 코드from collections import dequeimport sysinput = sys.stdin.readlineN = int(input())q = deque([])def command(com_list, queue): # push if len(com_list) > 1: if com_list[0] == 'push': queue.append(int(com_list[1])) # size, empty, pop, front, back else: if com_list[0] == 'pop': if queue: print(queue.pop.. 2024. 12. 10.
[Solved] BOJ: 2457 | 공주님의 정원 오랜만에 백준 풀이>,정렬 기반 빡구현 문제였다! 근데 문제 조건 잘 체크해야 함...난 부등호때문에 엄청 고생했다ㅠ.ㅠ문제3월 1일부터 11월 30일까지 매일 최소 1개 이상의 꽃이 피어있는 상태를 유지하도록 할 떄,꽃의 개수를 최소화하기입력첫째 줄에는 꽃들의 총 개수 N (1 ≤ N ≤ 100,000)이 주어진다. 다음 N개의 줄에는 각 꽃이 피는 날짜와 지는 날짜가 주어진다. 하나의 날짜는 월과 일을 나타내는 두 숫자로 표현된다. 예를 들어서, 3 8 7 31은 꽃이 3월 8일에 피어서 7월 31일에 진다는 것을 나타낸다.주의지는 날짜를 유의해야한다!! 지는 날짜 이전까지 꽃이 피어있는 것으로 친다.ex) 5월 8일 피어서 6월 13일 지는 꽃은 5월 8일부터 6월 12일까지는 꽃이 피어 있고, 6.. 2023. 12. 22.
728x90