九度 oj 题目1076:N的阶乘
来源:互联网 发布:java编程那些事儿 编辑:程序博客网 时间:2024/04/28 12:55
http://ac.jobdu.com/problem.php?pid=1076
#include <stdio.h>#include <string>#include <cstring>using namespace std;#define MAXN 99999typedef struct bign{ int d[MAXN]; bign(string s){ int len = (int) s.size() ; for (int i = len-1; i>=0; i--) { d[i+1] =s[(unsigned)i] - '0'; } d[0] = len; while(d[0]> 0 && d[d[0]] == 0 ) d[0]--; } bign(){ *this = bign("0"); } string toString(){ string s(""); for (int i = d[0]; i>=1;--i) { s = s + (char) (d[i]+'0'); } return s; } } Bign; Bign operator * (const Bign & a, int b){ Bign c; c.d[0] = a.d[0]; int x =0; for (int i = 1; i <=a.d[0]; ++i) { x = x + a.d[i]*b; c.d[i] = x%10; x = x/10; } while(x!=0){ c.d[++c.d[0]] = x%10; x /= 10; } return c;} int main(){ int n; while(scanf("%d",&n)!=EOF ){ Bign sum("1"); for (int i = 2; i <=n; ++i) { sum = sum * i; } string reString = sum.toString(); printf("%s\n",reString.c_str()); } }
注意因为 n最大到1000,所以较小的MAXN可以cover住,如果n很大,那么要考虑压缩。
0 0
- 九度oj 题目1076:N的阶乘
- 九度OJ 题目1076:N的阶乘
- 九度 oj 题目1076:N的阶乘
- 【九度OJ】题目1076:N的阶乘 解题报告
- 题目1076:N的阶乘 九度OJ
- 九度OJ 题目1067:n的阶乘
- 九度OJ—题目1067:n的阶乘
- 九度OJ 题目1067:n的阶乘
- 九度OJ-1076:N的阶乘
- 九度OJ-1076-N的阶乘
- 九度OJ 1076 n的阶乘
- 九度题目1076:N的阶乘
- 九度OJ 1067 n的阶乘
- 九度OJ 1067: n的阶乘
- 九度 OJ 1067:n的阶乘
- 九度oj-1067-n的阶乘
- 九度OJ 1076:N的阶乘(高精度计算)
- 九度OJ 1076 N的阶乘 -- 大数运算
- React Native学习笔记之--ListView和RefreshControl实现下拉刷新
- 如何在CentOS 6安装Linux,Apache,MySQL,PHP(LAMP)
- VS2015输入参数执行操作步骤
- unit 10
- oracle 创建分区表,增(追)加分区
- 九度 oj 题目1076:N的阶乘
- javascript中的函数(Function)
- 安卓手势识别
- php + 七牛上传遇到 nginx 413 nginx 413 Request Entity Too Large
- POJ3278:Catch That Cow(BFS)
- [LeetCode]442 Find All Duplicates in an Array
- Java 中方法的重载
- 2017-01-10 笔记 P2P网络 集中式网络与分散式网络
- unit 11