【題解】ZeroJudge c294: APCS-2016-1029-1三角形辨別

【題目敘述】https://zerojudge.tw/ShowProblem?problemid=c294
【解題想法】依照題敘提示的三角形邊長關係,判斷三線段能否構成三角形,亦可判斷是直角、銳角和鈍角三角形。。
【Tag】條件判斷

#include <iostream>
#include <algorithm>
using namespace std;
 
int main() {
    int a[3];
    for (int i=0; i<3; i++) {
        cin >> a[i];
    }
    sort(a, a+3);
     
    for (int i=0; i<3; i++) {
        cout << a[i] << " ";
    }
    cout << "\n";
    if (a[0]+a[1] < a[2]) {
        cout << "No\n";
    } else if (a[0]*a[0] + a[1]*a[1] == a[2]*a[2]) {
        cout << "Right\n";
    } else if (a[0]*a[0] + a[1]*a[1] > a[2]*a[2]) {
        cout << "Acute\n";
    } else {
        cout << "Obtuse\n";
    }
    return 0;
}

Python code

while True:
    try:
        lst = list(map(int, input().split()))
        lst.sort()
        a = lst[0]
        b = lst[1]
        c = lst[2]
        print(a, b, c)
        if a + b <= c:
            print('No')
        elif a ** 2 + b ** 2 < c ** 2:
            print('Obtuse')
        elif a ** 2 + b ** 2 == c ** 2:
            print('Right')
        elif a ** 2 + b ** 2 > c ** 2:
            print('Acute')
    except:
        break
分享本文 Share with friends