zoukankan      html  css  js  c++  java
  • 每日一九度之 题目1076:N的阶乘

    时间限制:3 秒

    内存限制:128 兆

    特殊判题:

    提交:7601

    解决:2749

    题目描述:

     输入一个正整数N,输出N的阶乘。

    输入:

    正整数N(0<=N<=1000)

    输出:

     输入可能包括多组数据,对于每一组输入数据,输出N的阶乘

    样例输入:
    4
    5
    15
    样例输出:
    24
    120
    1307674368000

    大数的乘法。

    //Asimple
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <cctype>
    #include <cstdlib>
    #include <stack>
    #include <cmath>
    #include <set>
    #include <map>
    #include <string>
    #include <queue>
    #include <limits.h>
    #define INF 0x7fffffff
    using namespace std;
    const int maxn = 3005;
    typedef long long ll;
    int n;
    ll a[maxn];
    
    int main(){
        while( ~scanf("%d",&n) ){
             if( n == 0 ){
                 printf("1
    ");
                 continue;
             }
             //进位 
             int c = 0, len = 1;
             memset(a,0,sizeof(a));
             a[0] = 1;
             for(int i=1; i<=n; i++){
                 c = 0;
                 for(int j=0; j<len; j++){
                     a[j] = a[j] * i + c;
                     if( a[j]>=10 ){
                         c = a[j] / 10;
                         a[j] = a[j] % 10;
                     } else c = 0;
                 }
                 while( c != 0 ){
                     int t = c % 10;
                     a[len++] = t;
                     c = c / 10;
                 }
             }
             int i, j;
             for(i=maxn; i>=0; i--){
                 if( a[i] != 0 ){
                     break;
                 }
             }
             for(j=i; j>=0; j--){
                 printf("%d",a[j]);
             }
             printf("
    ");
        } 
        return 0;
    }
    低调做人,高调做事。
  • 相关阅读:
    dom2级事件兼容性写法
    cookie js案例
    cookie讲解
    js高级总结
    鼠标拖拽时,选择文字问题
    正则的细节
    正则捕获的细节及replace分析
    正则的使用及replace细讲
    while循环的讲解
    acwing 189. 乳草的入侵 bfs
  • 原文地址:https://www.cnblogs.com/Asimple/p/5932768.html
Copyright © 2011-2022 走看看