import heapq
import itertools
class Patient:
_counter = itertools.count()
def __init__(self, name, pain_level):
self.name = name
self.pain_level = pain_level
self.arrival_order = next(Patient._counter)
def __lt__(self, other):
if self.pain_level == other.pain_level:
return self.arrival_order < other.arrival_order
return self.pain_level > other.pain_level
class Hospital:
def __init__(self):
self.waiting_list = []
def add_patient(self, patient):
heapq.heappush(self.waiting_list, patient)
def next_patient(self):
if self.waiting_list:
return heapq.heappop(self.waiting_list)
return None
hospital = Hospital()
patient_a = Patient("환자 A", 5)
patient_b = Patient("환자 B", 9)
patient_c = Patient("환자 C", 7)
hospital.add_patient(patient_a)
hospital.add_patient(patient_b)
hospital.add_patient(patient_c)
력
priority = 1
while True:
patient = hospital.next_patient()
if not patient:
break
print(f"환자 {patient.name}님이 우선순위 {priority}번으로 배정되었습니다. (긴급 상황)")
priority += 1
To embed this project on your website, copy the following code and paste it into your website's HTML: