K

@kimjuha19

로봇 이동

Python
4 months ago
def solution(R, C, moves): ur, uc = R, C for m in moves: if m == 'U': ur += 1 if m == 'D': ur -= 1 if m == 'R': uc += 1 if m == 'L':

중복 없는 가장 긴 명령어 찾기

Python
4 months ago
data = "pwwkew" answer = 1 max_idx = 0 for i in range(len(data)-1): if data[i] != data[i-1] and data[i] != data[i+1]: answer += 1 else: if answer > max_idx: max_idx = answer answer = 1

가장 큰 이벤트 응모 번호 만들기

Python
4 months ago
numbers = [10, 2, 21] numbers_str = [str(n) for n in numbers] for i in range(len(numbers_str)): for j in range(i+1, len(numbers_str)): if numbers_str[i] + numbers_str[j] < numbers_str[j] + numbers_str[i]: numbers_str[i],num

동아리 단체복 대여

Python
4 months ago
all = 10 lost = [3,8] have = [2,9] answer = all - len(lost) for i in range(len(lost)): if lost[i]+1 == have[i] or lost[i]-1 == have[i]: answer += 1

보드게임 주사위 이동

Python
4 months ago
dice = [1, 6, 2, 5, 4, 3] direction = ["남", "동", "북"] for i in direction: if i == "남": dice[0], dice[1], dice[2], dice[3] = dice[2], dice[3], dice[1], dice[0] elif i == "동": dice[0], dice[1], dice[4], dice[5] = dice[4], dice

간식 배부 명단 확인

Python
4 months ago
all = ["민지", "철수", "현아"] get = ["현아", "민지"] for i in range(len(all)): if all[i] not in get: print(all[i])

두 컴퓨터의 데이터 합산

Python
4 months ago
data1 = "1010" data2 = "1011" answer = 0 total = 0 for i in range(len(data1)): if data1[i] == "1": total += 2 ** (len(data1) - 1 - i) for i in range(len(data2)): if data2[i] == "1":

거꾸로 읽어도 똑같은 암호 코드

Python
4 months ago
input_data = "12345" answer = 0 for i in range(len(input_data) // 2): if input_data[i] != input_data[-1-i]: answer += 1 print(answer)

강의실 90도 구조 변경

Python
4 months ago
desk = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] n = len(desk) m = len(desk[0]) result = [[0] * n for i in range(m)] for i in range(n): for j in range(m): result[j][n-i-1] = desk[i][j]

거스름돈 최소 개수

Python
4 months ago
money = 800 coins = [500, 400, 100] min_count = float('inf') for a in range(money // 500 + 1): remaining1 = money - 500 * a for b in range(remaining1 // 400 + 1): remaining2 = remaining1 - 400 * b

다중 조건 성적 정렬

Python
4 months ago
students = [["Kim", 90, 80], ["Lee", 90, 85], ["Park", 80, 95]] students.sort(key=lambda x: (-x[1], -x[2], x[0])) for student in students: print(student[0])

행과 열의 합 비교

Python
4 months ago
lst = [[1, 2], [3, 4]] max_num = 0 for i in range(len(lst)): if sum(lst[i]) > max_num: max_num = sum(lst[i]) print(max_num)

최소 회의실 배정

Python
4 months ago
meetings = [[1, 3], [2, 4], [3, 5], [1, 2]] meetings.sort(key=lambda x: x[1]) count = 0 end_time = 0 for start, end in meetings: if start >= end_time: count += 1

괄호 짝 맞추기

Python
4 months ago
lst = "(())()" count = 0 for i in range(len(lst)): if lst[i] == "(": count += 1 else: count -= 1 if count == 0:

마름모 별 찍기

Python
4 months ago
N = 5 for i in range(1, N+1, 2): spaces = (N - i) // 2 print(" " * spaces + "*" * i) for i in range(N-2, 0, -2): spaces = (N - i) // 2 print(" " * spaces + "*" * i)

간단한 Run-Length 인코딩

Python
4 months ago
lst = "aaabbc" ans = "" c = 1; for n in range(1,len(lst)): if lst[n] == lst[n-1]: c += 1 else: ans += lst[n-1]+str(c) c = 1

소수 찾기

Python
4 months ago
N = 10 count = 0 for i in range(2, N): is_prime = True for j in range(2, int(i ** 0.5) + 1): if i % j == 0: is_prime = False break if is_prime:

10진수를 2진수로 변환

Python
4 months ago
N = 13 binary = "" while N > 0: remainder = N % 2 binary = str(remainder) + binary N = N // 2 print(binary)

행의 합이 최대인 곳 찾기

Python
4 months ago
list = [[1,2,3], [10,20,30], [5,5,5]] max_idx = 0 max_sum = 0 for i in range(len(list)): if sum(list[i]) > max_sum: max_sum = sum(list[i]) max_idx = i print(max_idx)

중복 제거와 순서 유지

Python
4 months ago
list = [5, 2, 8, 5, 1, 2, 10] answer = [] for i in list: if i not in answer: answer.append(i) print(answer)