https://github.com/tony9402/baekjoon/blob/main/picked.md
number = [(3, 5), (1, 2), (7, 2), (3, -1), (2, 3), (9, 6)]
# 첫 번째 원소를 기준으로 오름차순 정렬하고
# 첫 번째 원소가 같은 경우 두 번째 원소로 오름차순 정렬
number.sort()
print(number)
# 두 번째 원소를 기준으로 오름차순 정렬하고
# 두 번째 원소가 같은 경우 첫 번째 원소로 오름차순 정렬
number.sort(key=lambda x:(x[1], x[0]))
print(number)
# 첫 번째 원소를 기준으로 내림차순 정렬하고
# 첫 번째 원소가 같은 경우 두 번째 원소로 오름차순 정렬
number.sort(key=lambda x:(-x[0], x[1]))
print(number)
# 두 번째 원소를 기준으로 내림차순 정렬하고
# 두 번째 원소가 같은 경우 첫 번째 원소로 내림차순 정렬
number.sort(key=lambda x:(-x[1], -x[0]))
print(number)
출력 결과
[(1, 2), (2, 3), (3, -1), (3, 5), (7, 2), (9, 6)]
[(3, -1), (1, 2), (7, 2), (2, 3), (3, 5), (9, 6)]
[(9, 6), (7, 2), (3, -1), (3, 5), (2, 3), (1, 2)]
[(9, 6), (3, 5), (2, 3), (7, 2), (1, 2), (3, -1)]
N = int(input())
words = []
for i in range(N):
words.append(input())
set_words = list(set(words))
sort_words = []
for i in set_words:
sort_words.append((len(i), i))
sort_words.sort()
for len, word in sort_words:
print(word)
N = int(input())
pattern = input()
file = []
for i in range(N):
file.append(input())
pattern = pattern.split('*')
for i in file:
if len(i) >= len(pattern[0]) + len(pattern[1]) :
start = i[0:len(pattern[0])]
end = i[-len(pattern[1]):]
if pattern[0]==start and pattern[1]==end:
print("DA")
else:
print("NE")
else:
print("NE")
word = input()
split= []
for i in range(1, len(word)-1):
for j in range(i + 1, len(word)):
first = "".join(reversed(word[:i]))
second = "".join(reversed(word[i:j]))
third = "".join(reversed(word[j:]))
split.append(first+second+third)
split.sort()
print(split[0])
N, K = map(int, input().split())
course = list(map(int, input().split()))
length = sum(course) - 1
if K <= length:
num = 1
for i in course:
K = K - i
if K < 0:
break
else:
num += 1
else:
K = K - length - 1
num = N
for i in list(reversed(course)):
K = K - i
if K < 0:
break
else:
num -= 1
print(num)
from collections import deque
n = int(input())
one, two = map(int, input().split())
m = int(input())
graph = [[] for _ in range(n+1)]
for i in range(m):
x, y = map(int, input().split())
graph[x].append(y)
graph[y].append(x)
visited = [False] * (n+1)
visited[one] = True
queue = deque()
queue.append((0, one))
def bfs():
while queue:
cnt, x = queue.popleft()
for i in graph[x]:
if not visited[i]:
if i == two:
return cnt+1
else:
visited[i] = True
queue.append((cnt+1, i))
return -1
print(bfs())
from collections import deque
N, M = map(int, input().split())
graph = [[] for _ in range(N+1)]
for i in range(M):
A, B = map(int, input().split())
graph[B].append(A)
def counting(num):
visited = [False] * (N+1)
queue = deque()
visited[num] = True
queue.append(num)
cnt = 1
while queue:
x = queue.popleft()
for i in graph[x]:
if not visited[i]:
visited[i] = True
queue.append(i)
cnt += 1
return cnt
hack = []
for i in range(1, N+1):
count = counting(i)
hack.append(count)
max_count = max(hack)
max_list = [i for i, value in enumerate(hack) if value == max_count]
max_list.sort()
for i in max_list:
print(i+1, end=' ')