미용실과 레스토랑이 예약을 받는 기준은 다음과 같습니다.
□ 매개변수 설명
예약을 원하는 고객 정보가 담긴 리스트 customers와 shops가 solution 함수의 매개변수로 주어집니다.
□ return 값 설명
두 가게에서 예약받은 횟수를 return 해주세요.
# -*- coding: utf-8 -*-
# UTF-8 encoding when using korean
class Customer:
def __init__(self, id, time, num_of_people):
self.id = id
self.time = time
self.num_of_people = num_of_people
class Shop:
def __init__(self):
self.reserve_list = []
def reserve(self, customer):
self.reserve_list.append(customer)
return True
class HairShop(Shop):
def __init__(self):
super().__init__()
def reserve(self, customer):
if customer.num_of_people != 1:
return False
for r in self.reserve_list:
if customer.time == r.time:
return False
self.reserve_list.append(customer)
return True
class Restaurant(Shop):
def __init__(self):
super().__init__()
def reserve(self, customer):
if 2 <= customer.num_of_people <= 8:
return False
count = 0
for r in self.reserve_list:
if r.time == customer.time:
count += 1
if count >= 2:
return False
self.reserve_list.append(customer)
return True
def solution(customers, shops):
hairshop = HairShop()
restaurant = Restaurant()
count = 0
for customer, shop in zip(customers, shops):
if shop == "hairshop":
if hairshop.reserve(Customer(customer[0], customer[1], customer[2])):
count += 1
elif shop == "restaurant":
if restaurant.reserve(Customer(customer[0], customer[1], customer[2])):
count += 1
return count