N!

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 70861    Accepted Submission(s): 20321

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

求几十位数的阶乘,用数组保存每四位的数字,比如1320 0456 789,会变成list[0]=132,list[1]=456,list[2]=789;输出除了开头的那一组,其余用%04d(不足四位补0)。话说我不看大牛的代码也就只知道输出方式- -|||就当学习了。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
int list[40050]={1};//开始是1
int len;//总长度
void jiecheng(int a)
{
for (int i=0; i<=len; i++)
{
list[i]*=a;
if(list[i-1]>9999&&i>0)//若超过四位数
{
list[i]+=list[i-1]/10000;//先进一位
list[i-1]%=10000;//然后前一位取模
}
if(list[len]>=10000)
len++;
}
}
int main (void)
{
int n;
while (cin>>n)
{
memset(list,0,sizeof(list));//每次都清空一下,防止干扰
list[0]=1;
len=0;
for (int i=1; i<=n; i++)
{
jiecheng(i);
}
printf("%d",list[len]);//开头的一组正常输出
for (int i=len-1; i>=0; i--)
{
printf("%04d",list[i]);//不足四位补0
}
cout<<endl;
}
return 0;
}

HDU——1042N!(大数阶乘乘法)的更多相关文章

  1. HDU 1042 大数阶乘

    B - 2 Time Limit:5000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  2. HDU 1133 Buy the Ticket (数学、大数阶乘)

    Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  3. nyist28大数阶乘

    http://acm.nyist.net/JudgeOnline/problem.php?pid=28 大数阶乘 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 我们 ...

  4. 大数阶乘(c语言)

    大数阶乘.代码比较简单. #include<stdio.h> #include<string.h> #define MAXN 25000 // 如果你的阶乘N比较大,建议大一点 ...

  5. 【大数阶乘】NYOJ-28

    大数阶乘 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它?   输入 输入一个整数 ...

  6. 大数阶乘 nyoj

    大数阶乘 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它?   输入 输入一个整数 ...

  7. 【ACM】大数阶乘 - Java BigInteger实现

    大数阶乘 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它?   输入 输入一个整数 ...

  8. nyoj___大数阶乘

    http://acm.nyist.net/JudgeOnline/problem.php?pid=28 大数阶乘 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 我们都知 ...

  9. 大数阶乘(c++实现)

    #include <iostream>using namespace std;#define N 1000int BigNumFactorial(int Num[], int n);voi ...

随机推荐

  1. GPnP profile内容

    <?xml version="1.0" encoding="UTF-8"?>  <gpnp:GPnP-Profile Version=&quo ...

  2. GIT分布式版本控制器的前后今生

    Git的入门与安装 GIT基础操作 GIT的分支应用 GITLAB应用 gitlab与pycharm应用 GITHUB使用

  3. Ecshop首页购物车数量调取问题

    在page_header.lbi中调用SQL: <?php $sql = 'SELECT SUM(goods_number) AS number' . ' FROM ' . $GLOBALS[' ...

  4. 分类回归树(CART)

    概要 本部分介绍 CART,是一种非常重要的机器学习算法.   基本原理   CART 全称为 Classification And Regression Trees,即分类回归树.顾名思义,该算法既 ...

  5. 用户输入和while循环

    函数input()的工作原理 message=input('Tell me something,and I will repeat it back to you:') print(message) 编 ...

  6. vs2015驱动开发中使用RtlStringCchPrintfW()报错

    法一: 在头顶添加一段代码 #pragam comment(lib,"xxxxxx.lib") 法二: 右击工程点属性,选择Linker下的Input,在依赖项后面写上$(DDK_ ...

  7. iOS调用WebService接口

    首先有几点说在前面 一般,在请求URL的后面带有WSDL字样的需要调用WebService URL样式例子:http://ip:port/navigable/webservice/loginSeric ...

  8. 数组char a[4] 保存了一个数据,怎么转换为unsigned int呢 ?

    [待解决问题] 浏览: 701次 注意char并不表示字符的 a[0]=0; a[1]=0; a[2]=3; a[3]=0; 那么我要的unsigned int b应该等于: b= 0x0000030 ...

  9. 【Git版本控制】Git的merge合并分支命令

    1.实例 git checkout master git merge dev merge合并分支只对当前分支master产生影响,被合并的分支dev不受影响. 假设你有两个分支,“stable” 和 ...

  10. python入门:输出1-100之内的所有奇数和偶数

    #!/usr/bin/env python # -*- coding:utf-8 -*- #输出1-100之内的所有奇数和偶数 """ 给start赋值等于1,while ...