import heapq
class ComplexNum():
def __init__(self, real, imag):
self.real = real
self.imag = imag
def __lt__(self, other):
if self.real**2 + self.imag**2 != other.real**2 + other.imag**2:
return self.real**2 + self.imag**2 > other.real**2 + other.imag**2
else:
return self.real > other.real
def __repr__(self):
return str(self.real) + '+i' + str(self.imag)
def main():
n = int(input().strip())
numsList = list()
for i in range(n):
command = input().strip()
if 'Pop' in command:
if len(numsList)==0:
print('empty')
else:
item = heapq.heappop(numsList)
print(item)
print('SIZE = {}'.format(len(numsList)))
elif 'Insert' in command:
num = command.split()[1]
real, imag = num.split('+i')
heapq.heappush(numsList, ComplexNum(real=eval(real), imag=eval(imag)))
print('SIZE = {}'.format(len(numsList)))
if __name__=='__main__':
try:
while True:
main()
except:
pass
KY196 复数集合
最新推荐文章于 2024-11-03 20:27:08 发布