공부(140)
-
[PCCE 기출문제] 9번 / 이웃한 칸 - Python
1. 풀이 코드def solution(board, h, w): answer = 0 up_cell = board[h - 1][w] if h - 1 >= 0 else 'x' down_cell = board[h + 1][w] if len(board) > h + 1 else 'x' left_cell = board[h][w - 1] if w - 1 >= 0 else 'x' right_cell = board[h][w + 1] if len(board) > w + 1 else 'x' for item in [up_cell, down_cell, left_cell, right_cell]: if item == board[h][w]: answer += 1 r..
2024.11.22 -
알고리즘 가이드: 주요 접근 방법 정리
보호되어 있는 글입니다.
2024.11.22 -
체육복 - Python
1. 풀이 코드def solution(n, lost, reserve): answer = 0 student_list = [1 for _ in range(n)] for lost_index in lost: lost_index -= 1 student_list[lost_index] -= 1 for reserve_index in reserve: reserve_index -= 1 student_list[reserve_index] += 1 if student_list[0] == 2 and student_list[1] == 0: student_list[0] = 1 student_list[1] = 1..
2024.11.22 -
30970 선택의 기로 - Python
1. 풀이 코드N = int(input())quality = []quantity = []for _ in range(N): qual, quan = map(int, input().split(' ')) quality.append([qual, quan]) quantity.append([quan, qual])quality.sort(key=lambda x: (-x[0], x[1]))quantity.sort(key=lambda x: (x[0], -x[1]))# print(quality)# print(quantity)print(f"{quality[0][0]} {quality[0][1]} {quality[1][0]} {quality[1][1]}")print(f"{quantity[0][1]} {quanti..
2024.08.06 -
26150 Identify, Sort, Index, Solve - Python
1. 풀이 코드N = int(input())answer = ["0"] * Ntemp_list = []for i in range(N): message, num_i, num_d = input().split(' ') temp_list.append([int(num_i), num_d, message])temp_list.sort()for i in range(N): j = int(temp_list[i][1]) - 1 # print(j, temp_list[i][2]) answer[i] = temp_list[i][2][j].upper()print(''.join(answer)) 디버깅으로 사용한 코드는 주석처리하였습니다. 2. 다른 사람 풀이 코드for i,j,k in sorted(map(st..
2024.08.06 -
1384 메시지 - Python
1. 풀이 코드num = 0while True: is_bullying = False n = int(input()) num += 1 if n == 0: break people_list = [] for i in range(n): paper = list(input().split(' ')) people_list.append(paper) print(f"Group {num}") for i in range(n): target = people_list[i] for j in range(n): if target[j] == "N": is_bullying..
2024.08.06 -
23882 알고리즘 수업 - 선택 정렬 2 - Python
1. 풀이 코드change_count = 0N, K = map(int, input().split(' '))num_list = list(map(int, input().split(' ')))i = 0is_search = Falsewhile True: target_num = num_list[N-1-i] if N-1-i == 0: break next_max_num = max(num_list[:N-1-i]) if target_num 2. 다른 사람 풀이 코드a, b = map(int, input().split())lst = list(map(int, input().split()))count = 0for i in range(a-1, 0, -1): max_index = ls..
2024.08.06