목록Python/백준 (129)
가오리의 코딩일기
import sys n = int(sys.stdin.readline()) data = [list(sys.stdin.readline().split()) for _ in range(n)] data.sort(key=lambda a: (-int(a[1]), int(a[2]), -int(a[3]), a[0])) for i in data: sys.stdout.write(str(i[0])+'\n')
n = int(input()) data = [] for i in range(n): age, name = map(str, input().split()) age = int(age) data.append((age, name)) data.sort(key=lambda x: x[0]) # (age, name)에서 age만 비교 for i in data: print(i[0], i[1])
import sys n = int(sys.stdin.readline()) data = [] for i in range(n): [a, b] = map(int, sys.stdin.readline().split()) data.append([b, a]) sorted_data = sorted(data) for b, a in sorted_data: print(a, b)
import sys n = int(sys.stdin.readline()) data = [] for i in range(n): [a, b] = map(int, sys.stdin.readline().split()) data.append([a, b]) sorted_data = sorted(data) for i in range(n): print(sorted_data[i][0], sorted_data[i][1])
import sys n = int(input()) data = [] for i in range(n): data.append(int(sys.stdin.readline())) for i in sorted(data): sys.stdout.write(str(i)+'\n')
T = int(input()) for i in range(T): a = list(input()) sum = 0 for i in a: if i =='(': sum+=1 elif i ==')': sum -=1 if sum 0: print("NO") elif sum == 0: print("YES") - 괄호를 열고 괄호를 닫을 때 +1과 -1을 해주고 sum을 0일 때와 아닐 때를 기준으로 구분한다
import sys N = int(sys.stdin.readline()) # N = int(input()) stack = [] for _ in range(N): # word = input().split() word = sys.stdin.readline().split() order = word[0] if order == "push": value = word[1] stack.append(value) elif order == "pop": if len(stack) == 0: print(-1) else: print(stack.pop()) elif order == "size": print(len(stack)) elif order == "empty": if len(stack) == 0: print(1) else: p..
n, k = map(int, input().split()) data = list(map(int, input().split())) data.sort() print(data[k-1])
n = int(input()) dic ={} for case in range(n): card = int(input()) if card in dic: dic[card] += 1 else: dic[card] = 1 dic = sorted(dic.items(), key = lambda x: (-x[1], x[0])) print(dic[0][0])
메모리 초과 오류 import sys n = int(sys.stdin.readline()) data = [] for _ in range(n): data.append(int(sys.stdin.readline().split())) sorted_data = sorted(data) for i in sorted_data: print(i) import sys n = int(sys.stdin.readline()) data = [0] * 10001 for _ in range(n): data[int(sys.stdin.readline())] +=1 for i in range(10001): if data[i] != 0: for j in range(data[i]): print(i)