Here is a possible implementation in Python:

import math

def calculate_area(shape, a, b):
    if shape == 'C':
        return math.pi * a**2
    elif shape == 'R':
        return a * b
    else:
        return 0

def total_area():
    n = int(input())
    total = 0

    for _ in range(n):
        shape, a, b = input().split()
        a = int(a)
        b = int(b) if b != '' else 0
        total += calculate_area(shape, a, b)

    return round(total, 2)

print(total_area())

Example input:

3
C 5
R 3 4
C 2

Example output:

60.85
``
A program that calculates the total area of a set of geometric shapes whose type and dimensions are provided The geometric shapes can be circles or rectangles The program should return the total area

原文地址: https://www.cveoy.top/t/topic/h86c 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录