-
알고리즘 & 자료구조 스터디(10조) 6일차알고리즘 2023. 5. 27. 21:16
Q. 1037 약수 구하기
약수를 구할 때는 제일 큰수 * 제일 작은수가 포인트입니다.
n = int(input()) t = list(map(int, input().split())) t.sort() if len(t) % 2 == 0: answer = t[0] * t[-1] else: num = len(t) // 2 answer = t[num] print(answer)
Q. 1874 스택수열
누군가 그랬다 이중반복문은 일단 틀릴 가능성이 높다고 근데 이거 왜 이중반복문이냐...
while 반복문에서 or 하나 못생각해내서 힘들어죽을 뻔 했다
T = int(input()) stacknumList = [] stack = [] checkList = [] for _ in range(T): stacknumList.append(int(input())) i = 1 for num in stacknumList: while ( not stack ) or ( stack[-1] < num ): stack.append(i) checkList.append("+") i += 1 if stack[-1] == num: stack.pop() checkList.append("-") elif stack[-1] > num: print("NO") break else: for i in checkList: print(i)
'알고리즘' 카테고리의 다른 글
알고리즘 & 자료구조 스터디(10조) 8일차 (0) 2023.05.30 알고리즘 & 자료구조 스터디(10조) 7일차 (0) 2023.05.29 알고리즘 & 자료구조 스터디(10조) 5일차 (0) 2023.05.26 알고리즘 & 자료구조 스터디(10조) 4일차 (1) 2023.05.25 알고리즘 & 자료구조 스터디(10조) 3일차 (0) 2023.05.24