cospro 3

[Python]COS_PRO_기출2회차[6-10]풀이

6번 로봇을 움직여주세요 뇌 안쓰고 간단하게 만든 def solution(commands): answer = [0,0] for c in list(commands) : if c == 'L' : answer[0]-=1 elif c== 'R' : answer[0]+=1 elif c== 'U' : answer[1]+=1 else : answer[1]-=1 return answer 글자와 방향을 zip으로 묶고 dict를 이용해서 딕셔너리로 만든다. 딕셔너리의 key를 이용해서 dx,dy를 구하고 rx,ry에 연산한다. def solution(commands): answer = [0,0] move = dict(zip('LRUD',[[-1,0],[1,0],[0,1],[0,-1]])) rx,ry = 0,0 for c..

[Python]COS_PRO_기출2회차[1-5]풀이

1번 도서 대여점 운영 class Book(metaclass=ABCMeta): @abstractmethod def get_rental_price(self, day): pass class ComicBook(Book): def get_rental_price(self,day): cost = 500 day -= 2 if day > 0: cost += 200*day return cost class Novel(Book): def get_rental_price(self,day): cost = 1000 day -= 3 if day > 0: cost += 300*day return cost 2번 지하철 기다리기 def solution(subway_times, current_time): current_minute = fu..

[Python]COS_PRO_기출 1회차 [1-5]풀이

1번 . 음식 전문점 상속을 받을 때 Class PizzaStore(DeliveryStore) : 이런식으로 인터페이스 이름( DeliveryStore)을 매개변수로 준다. 클래스 내부의 메서드의 선언부는 해당 인터페이스의 추상 메서드와 동일한 선언부로 선언해준다!! def set_order_list(self, order_list): for order in order_list: self.order_list.append(order) def get_total_price(self): total_price = 0 for order in self.order_list: for menu in self.menu_list: if order == menu.name: total_price += menu.price retur..