2012/03/03

[zerojudge] d122 Oh! My Zero!!

題目:https://zerojudge.tw/ShowProblem?problemid=d122
說明:會有 0 就是 2 * 5 時發生,判斷 n! 時有幾個 2 及幾個 5,一般來說是 5 比較少,只要計算有幾個 5 即可。

Java 版
import java.util.Scanner;

public class D122 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            String input = in.nextLine();
            int a = Integer.parseInt(input);
            int r = 0;
            while(a!=0){
                r = r + a/5;
                a = a/5;
            }
            System.out.println(r);
        }
    }
}
Python 版 (2022.07)
while True:
    try:
        a = int(input())
        lst = list(sorted(map(int, input().split(' '))))
        for i in range(a):
            print(lst[i], end=' ')
        print()
    except EOFError:
        break

沒有留言:

張貼留言