编程介的小学生 2020-02-26 07:46 采纳率: 0.4%
浏览 110

Draw Something 关于绘图的问题

Problem Description
Wangpeng is good at drawing. Now he wants to say numbers like “521” to his girlfriend through the game draw something.
Wangpeng can’t write the digit directly. So he comes up a way that drawing several squares and the total area of squares is the number he wants to say.
Input all the square Wangpeng draws, what’s the number in the picture?

Input
There are multiple test cases.
For each case, the first line contains one integer N(1≤N≤100) indicating the number of squares.
Second line contains N integers ai(1≤ai≤100)represent the side length of each square. No squares will overlap.
Input ends with N = 0.

Output
For each case, output the total area in one line.

Sample Input
4
1 2 3 4
3
3 3 3
0

Sample Output
30
27

  • 写回答

1条回答 默认 最新

  • 码农阿豪@新空间 优质创作者: Java、后端开发技术领域 2024-07-25 20:10
    关注
    让阿豪来帮你解答,本回答参考chatgpt3.5编写提供,如果还有疑问可以评论或留言
    ```python

    Function to calculate the total area of squares based on input

    def total_area_of_squares(N, sides): total_area = 0 for side in sides: total_area += side * side return total_area

    Input processing

    while True: N = int(input()) if N == 0: break sides = list(map(int, input().split())) # Calculate total area of squares and output result result = total_area_of_squares(N, sides) print(result)

    Sample Input
    

    4 1 2 3 4 3 3 3 3 0

    Sample Output
    

    30 27

    评论

报告相同问题?