COS PRO 1급 기출문제 - Python - 구름EDU
YBMIT에서 시행하는 COS Pro 자격증으로 기출문제를 직접 풀어볼 수 있는 실습 위주의 강좌입니다.
edu.goorm.io
문제 1) 음식전문점 운영
class DeliveryStore(metaclass=ABCMeta):
@abstractmethod
def set_order_list(self, order_list):
pass
@abstractmethod
def get_total_price(self):
pass
class Food:
def __init__(self, name, price):
self.name = name
self.price = price
class PizzaStore(DeliveryStore): # 빈칸 채우기 (상속)
def __init__(self):
menu_names = ["Cheese", "Potato", "Shrimp", "Pineapple", "Meatball"]
menu_prices = [11100, 12600, 13300, 21000, 19500];
self.menu_list = []
for i in range(5):
self.menu_list.append(Food(menu_names[i], menu_prices[i]))
self.order_list = []
def set_order_list(self, order_list): # 빈칸 채우기 (self와 order_list)
for order in order_list:
self.order_list.append(order)
def get_total_price(self): # 빈칸 채우기 (함수명, self)
total_price = 0
for order in self.order_list:
for menu in self.menu_list:
if order == menu.name:
total_price += menu.price
return total_price
def solution(order_list):
delivery_store = PizzaStore()
delivery_store.set_order_list(order_list)
total_price = delivery_store.get_total_price()
return total_price
문제 4) 타임머신
def solution(num):
num_str_list = list(str(num+1))
for i in range(len(num_str_list)):
if num_str_list[i] == '0':
num_str_list[i] = '1'
return int(''.join(num_str_list))
num = 9949999;
ret = solution(num)
print("solution 함수의 반환 값은", ret, "입니다.") # 9951111
문제 5) 소용돌이 수
n = 3, 4, 5 일 경우들 각각 덧셈 과정 구해보면서, 대각선 값들만 규칙 세워서 더하기
def solution(n):
ans = 1
tmp_num = 1
plus_num = 2 * n + 2
for i in range(1, n):
if i % 2 == 1:
plus_num -= 4
tmp_num += plus_num
ans += tmp_num
return ans
n1 = 3
ret1 = solution(n1)
print("solution 함수의 반환 값은", ret1, "입니다.") # 15
n2 = 2
ret2 = solution(n2)
print("solution 함수의 반환 값은", ret2, "입니다.") # 4
문제 6) 체스의 나이트
def solution(pos):
x = 8 - int(pos[1])
y = ord(pos[0]) - ord('A')
dx = [-2, -1, 1, 2, 2, 1, -1, -2]
dy = [1, 2, 2, 1, -1, -2, -2, -1]
cnt = 0
for i in range(8):
nx = x + dx[i]
ny = y + dy[i]
if nx in range(8) and ny in range(8):
cnt += 1
return cnt
pos = "A7"
ret = solution(pos)
print("solution 함수의 반환 값은", ret, "입니다.") # 3
문제 7) 병합 and 정렬
def solution(arrA, arrB):
arrA_idx = 0
arrB_idx = 0
arrA_len = len(arrA)
arrB_len = len(arrB)
answer = []
while arrA_idx != arrA_len and arrB_idx != arrB_len: # 조건 채우기
if arrA[arrA_idx] < arrB[arrB_idx]:
answer.append(arrA[arrA_idx])
arrA_idx += 1
else:
answer.append(arrB[arrB_idx])
arrB_idx += 1
while arrA_idx != arrA_len: # 조건 채우기
answer.append(arrA[arrA_idx])
arrA_idx += 1
while arrB_idx != arrB_len: # 조건 채우기
answer.append(arrB[arrB_idx])
arrB_idx += 1
return answer
arrA = [-2, 3, 5, 9]
arrB = [0, 1, 5]
ret = solution(arrA, arrB);
print("solution 함수의 반환 값은", ret, "입니다.")