2012/02/21

[zerojudge] d051 糟糕,我發燒了!

題目:https://zerojudge.tw/ShowProblem?problemid=d051
說明:如何控制 double 輸出的格式。

Java 版
import java.util.Scanner;

public class D051 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            long a = Integer.parseInt(in.nextLine());
            double r = (a - 32) * 5 / 9.0;
            System.out.printf("%.3f\n",r);
        }
    }
}
Python 版 (2022.07)
while True:
    try:
        a = int(input())
        r = (a - 32) * 5 / 9.0
        print('%.3f' % r)
    except:
        break

沒有留言:

張貼留言