/ SeriousOJ /

Record Detail

Compile Error

foo.c:1:1: error: unknown type name 'def'
    1 | def find_triangle_perimeter(base):
      | ^~~
foo.c: In function 'find_triangle_perimeter':
foo.c:1:34: error: expected declaration specifiers before ':' token
    1 | def find_triangle_perimeter(base):
      |                                  ^
foo.c:3:11: error: invalid preprocessing directive #If; did you mean #if?
    3 |         # If base is even, we can form a right-angled triangle with base/2, base/2, and hypotenuse = base
      |           ^~
      |           if
foo.c:8:11: error: invalid preprocessing directive #If; did you mean #if?
    8 |         # If base is odd, we can form a right-angled triangle with (base-1)/2, (base+1)/2, and hypotenuse = base
      |           ^~
      |           if

Code

def find_triangle_perimeter(base):
    if base % 2 == 0:
        # If base is even, we can form a right-angled triangle with base/2, base/2, and hypotenuse = base
        height = base // 2
        hypotenuse = base
        return height + hypotenuse + base
    else:
        # If base is odd, we can form a right-angled triangle with (base-1)/2, (base+1)/2, and hypotenuse = base
        height = (base - 1) // 2
        hypotenuse = base
        return height + hypotenuse + base

def main():
    T = int(input("Enter the number of testcases: "))
    
    for _ in range(T):
        B = int(input())
        perimeter = find_triangle_perimeter(B)
        print(perimeter if perimeter > 0 else -1)

if __name__ == "__main__":
    main()

Information

Submit By
Type
Submission
Problem
P1027 Right triangle
Contest
Brain booster #2
Language
C99 (GCC 13.2.0)
Submit At
2024-03-06 14:24:47
Judged At
2024-11-11 03:41:59
Judged By
Score
0
Total Time
0ms
Peak Memory
0 Bytes