2012/03/05

[zerojudge] d489 伏林的三角地

題目:https://zerojudge.tw/ShowProblem?problemid=d489
說明:數學題,用海龍公式,最後要轉成 int 輸出。

Java 版
import java.util.Scanner;

public class D489 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            String[] str = in.nextLine().split(" ");
            double a = Double.parseDouble(str[0]);
            double b = Double.parseDouble(str[1]);
            double c = Double.parseDouble(str[2]);
            double s = 0.5 * (a + b + c);
            double r = s * (s-a) * (s-b) * (s-c);
            System.out.println((int) r);
        }
    }
}
Python 版 (2022.07)
a, b, c = map(int, input().split(' '))
s = 0.5 * (a+ b + c)
r = s * (s-a) * (s-b) * (s-c)
print(int(r))

沒有留言:

張貼留言