Shape Area Total
Programming Interview
Easy
8 views
Problem Description
You will get q shapes. Each line: RECT w h, CIRC r, or SQR a. Print total area with 2 decimals.
Input Format
See description.
Output Format
See description.
Sample Test Case
Input:
3
RECT 3 4
CIRC 1
SQR 2
Constraints
Total operations up to 200000.
Official Solution
import sys, math
lines=sys.stdin.read().splitlines()
if not lines or not lines[0].strip():
sys.exit(0)
q=int(lines[0].strip())
total=0.0
for i in range(1,1+q):
parts=(lines[i] if i < len(lines) else '').split()
if not parts:
continue
t=parts[0]
if t=='RECT':
total += float(parts[1]) * float(parts[2])
elif t=='CIRC':
r=float(parts[1])
total += math.pi * r * r
else:
a=float(parts[1])
total += a * a
sys.stdout.write(f'{total:.2f}')
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!