zoukankan      html  css  js  c++  java
  • 高精度练习(hdoj1042)

    Problem Description
    Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!
     
    Input
    One N in one line, process to the end of file.
     
    Output
    For each N, output N! in one line.
     
    Sample Input
    1
    2
    3
     
    Sample Output
    1
    2
    6
     
    #include <stdio.h>
    #include <stdlib.h>
    char* myblog[] = {
        "http://www.cnblogs.com/archimedes/",
        "hdoj1042",
        "mail: codingwu@gmail.com"};
    
    int a[50000];
    
    void count(int n)
    {
        int i, flag, digit, j, t;
        a[0] = 1;
        digit = 1;
        j = 1;
        for(i = 2; i <= n; i++) {
            flag = 0;
            for(j = 0; j < digit; j++) {
                t = a[j] * i + flag;
                if(t >= 10) {
                    a[j] = t % 10;
                    flag = t / 10;
                } else {
                    a[j] = t;
                    flag = 0;
                }
            }
            if(flag) {
                while(flag) {
                    a[j] = flag % 10;
                    flag /= 10;
                    digit++;
                    j++;
                }
            }
        }
        for(i = j - 1; i >= 0; i--)
            printf("%d", a[i]);
        printf("
    "); 
    }
    
    void solve()
    {
        int n;
        while(scanf("%d", &n) != EOF) {
            if(n == 0) printf("1
    ");
            else count(n);
        }
    }
    
    int main()
    {
        solve();
        return 0;
    }
  • 相关阅读:
    psi
    firefox修改语言
    automapper
    堆喷图解
    脱壳系列_0_FSG壳_详细版
    脱壳系列_1_UPX壳_详细版
    算法01-最大子数组详解
    逆向MFC程序
    如何执行shell命令
    Unity之流光效果
  • 原文地址:https://www.cnblogs.com/wuyudong/p/hdoj1042.html
Copyright © 2011-2022 走看看