Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- django
- C++
- cos pro
- issue
- Python
- 알고리즘
- AndroidStudio
- DFS와BFS
- 분할정복
- 안드로이드스튜디오
- 코테
- cos
- 코딩테스트
- cos pro 1급
- BAEKJOON
- DFS
- vuejs
- 동적계획법
- android
- 동적계획법과최단거리역추적
- Algorithm
- 안드로이드
- 파이썬
- codingtest
- 백준
- DART
- 개발
- Vue
- Flutter
- 코드품앗이
Archives
- Today
- Total
Development Artist
[COS Pro 1급, Python] 2차 1번 : 도서 대여점 운영 본문
728x90
반응형
문제 유형
빈칸
난이도
easy
Note
1. 파이썬의 Class, def, self
Code
# -*- coding: utf-8 -*-
# UTF-8 encoding when using korean
# 2차 1번
from abc import *
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
def solution(book_types, day):
books = []
for types in book_types:
if types == "comic":
books.append(ComicBook())
elif types == "novel":
books.append(Novel())
total_price = 0
for book in books:
total_price += book.get_rental_price(day)
return total_price
book_types = ["comic", "comic", "novel"]
day = 4
ret = solution(book_types, day)
print("solution 함수의 반환 값은", ret, "입니다.")
※ 가끔 코드 중 print(~)가 있습니다. 정리 못한 점 죄송합니다.
728x90
반응형
'Algorithm > COS' 카테고리의 다른 글
[COS Pro 1급, Python] 2차 3번 : 경품 당첨자를 구해주세요 (0) | 2022.02.25 |
---|---|
[COS Pro 1급, Python] 2차 2번 : 지하철 기다리기 (0) | 2022.02.25 |
[COS Pro 1급, Python] 1차 10번 : 주식으로 최대 수익을 내세요 (0) | 2022.02.24 |
[COS Pro 1급, Python] 1차 9번 : 계단 게임 (0) | 2022.02.24 |
[COS Pro 1급, Python] 1차 8번 : 누가 당선 되나요 (0) | 2022.02.24 |
Comments