2012/02/14

[zerojudge] a034 二進位制轉換

題目:https://zerojudge.tw/ShowProblem?problemid=a034
說明:Java 中套用 Integer 的函式,Python 則改變輸出的格式設定。

Java 版
import java.util.Scanner;
 
public class A034 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            System.out.println(Integer.toBinaryString(in.nextInt()));
        }    
    }
}
Python 版
while True:
    try:
        a = int(input())
        print(format(a, 'b'))
    except:
        break

沒有留言:

張貼留言