Compare Complex Magnitudes
Python
Hard
2 views
Problem Description
Two complex numbers are provided as a b and c d (a+bi and c+di). Output FIRST if first magnitude is bigger, SECOND if second bigger, else EQUAL.
Input Format
One line: a b c d.
Constraints
Values fit in 64-bit.
Official Solution
import sys
p=sys.stdin.read().strip().split()
if not p: sys.exit(0)
a=int(p[0]); b=int(p[1]); c=int(p[2]); d=int(p[3])
m1=a*a+b*b
m2=c*c+d*d
if m1==m2:
sys.stdout.write('EQUAL')
elif m1>m2:
sys.stdout.write('FIRST')
else:
sys.stdout.write('SECOND')
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!