K

@kimjuha19

부족한 금액 계산하기

Python
5 months ago
def calc_money(price, money, count): total = 0 for i in range(1,count+1): total += price * i answer = total - money return answer price=3 money=20

소수 에라토스테네스의 체

Python
5 months ago
def count_primes(n): answer = 0 for i in range(2,n): if i % 2 != 0: answer += 1 return answer n = 10 ret = count_primes(n) print(ret)

성적 통계 처리

Python
5 months ago
def top_students(score_dict): total = 0 count = 0 for score in score_dict.values(): total += score count += 1 avg = total / count

로봇 청소기 동선

Python
5 months ago
def robot_move(n, commands): x = 1 y = 1 for i in range(len(commands)): if commands[i] == "R" and x + 1 <= n: x += 1 elif commands[i] == "L" and x - 1 >= 1: x -= 1 elif commands[i] == "U"

가사 검색

Python
5 months ago
def count_matching_word(words, keyword): count = 0 for i in range(len(words)): if len(keyword) == len(words[i]): count += 1 return count words = ["apple", "banana", "cherry"]

주식 수익률 극대화

Python
5 months ago
def max_profit(prices): max_profit = 0 for i in range(len(prices)): for j in range(i + 1, len(prices)): profit = prices[j] - prices[i] if profit > max_profit: max_profit = profit return m

응급실 진료 순서

Python
5 months ago
def emergency_order(data, target): high = 0 for i in range(len(data)): if high < data[i]: high = data[i] target = i return target

Getter와 Setter

Python
5 months ago
class User: def __init__(self, password): self._password = password def get_password(self): return "비밀번호는 직접 확인할 수 없습니다." def set_password(self, new_password): if len(new_password) < 8: print("비밀번호는

고유 ID 부여

Python
5 months ago
class Item: serial_counter = 1000 def __init__(self): Item.serial_counter += 1 self.id_number = Item.serial_counter item1 = Item() item2 = Item() item3 = Item()

데이터 로드

Python
5 months ago
class Person: def __init__(self, data): name, age, city = data.split(',') self.name = name self.age = int(age) self.city = city data = "홍길동,20,서울" person = Person(data)

클래스 변수의 활용

Python
5 months ago
class Discount: def __init__(self, discount): self.discount = discount self.new_discount_rate = discount def discount_rate(self, discount): self.new_discount_rate = self.new_discount_rate * discount // 100 def d

생성 시 시간 기록

Python
5 months ago
import datetime class Time: def __init__(self): self.created_at = datetime.datetime.now() def display_time(self): print(self.created_at)

주소록 시스템

Python
5 months ago
class Contact: def __init__(self): self.contact = [] def add_phone(self,number): new_number = {'number': number} self.contact.append(new_number) def display_number(self): for i in self.contact:

나이 설정기

Python
5 months ago
class Age: def __init__(self, age): self.age = age def set_age(self, new_age): if new_age < 0 or new_age > 200: print("잘못된 입력입니다") else: self.age = new_age

누가 더 큰가?

Python
5 months ago
class Rectangle: def __init__(self, width, height): self.width = width self.height = height def area(self): return self.width * self.height def compare_area(self, other): if self.area() >= other.area():

최단 비행 경로

Python
5 months ago
import heapq def cheapest_flight(flights, start, end): graph = {} for a, b, cost in flights: if a not in graph: graph[a] = [] graph[a].append((b, cost))

적록색약 색상 구분

Python
5 months ago
def color_analysis(colors): n = len(colors) grid = [list(row) for row in colors] dx = [1, -1, 0, 0] dy = [0, 0, 1, -1] def dfs(x, y, grid, visited): stack = [(x, y)] visited[x][y] = True

단어 변환 게임

Python
5 months ago
from collections import deque def find_word_path(begin, target, words): if target not in words: return 0 q = deque() q.append((begin, 0)) visited = set() visited.add(begin)

네트워크 연결 비용

Python
5 months ago
def min_bridge_cost(n, costs): costs.sort(key=lambda x: x[2]) parent = [i for i in range(n)] def find(x): if parent[x] != x: parent[x] = find(parent[x]) return parent[x]

보석 쇼핑

Python
5 months ago
def find_shortest_range(gems): unique_count = len(set(gems)) count = {} left = 0 best = (0, len(gems)-1) for right in range(len(gems)): count[gems[right]] = count.get(gems[right], 0) + 1