Home

[백준] 별 찍기-19

문제 n = int(input()) size = 4 * n - 3 map = [[' '] * size for _ in range(size)] def draw_star(n, r, c): # r과 c는 현재 크기의 좌측상단 좌표 if n == 1: map[r][c] = '*' return length = 4 * n - 3 # 바깥 테두리 그리기 for i in range(length): map[r][c + i] = '*' # 위쪽 가로줄 map[r + length - 1][c + i] = '*' # 아래쪽 가...

Read more

[백준] 단어 나누기

문제 s = input() words = [] for i in range(1, len(s)- 1): for j in range(i + 1, len(s)): s1 = s[:i] s2 = s[i:j] s3 = s[j:] words.append(s1[::-1] + s2[::-1] + s3[::-1]) print(min(words))

Read more

[백준] 단어 정렬

문제 n = int(input()) word_dict = {} for i in range(n): word = input() length = len(word) if length not in word_dict.keys(): word_dict[length] = [word] else: word_dict[length].append(word) for key in sorted(word_dict.keys()): for word in sorted(set(word_dict[key])): print(word)

Read more

[백준] 막대기

문제 x = int(input()) sticks = [64] while sum(sticks) > x: shortest = min(sticks) half = shortest // 2 sticks.remove(shortest) sticks.append(half) sticks.append(half) if sum(sticks[:-1]) >= x: sticks.pop() print(len(sticks))

Read more

[백준] 다리 놓기

문제 t = int(input()) def factorial(n): if n == 0: return 1 return n * factorial(n - 1) def comb(n, m): return factorial(n) // (factorial(m) * factorial(n - m)) for i in range(t): n, m = map(int, input().split()) print(comb(m, n))

Read more