CodeChef - Small factorials
来源:互联网 发布:尔湾 知乎 编辑:程序博客网 时间:2024/06/03 22:02
题目:http://www.codechef.com/problems/FCTRL2/
You are asked to calculate factorials of some small positive integers.
Input
An integer t, 1<=t<=100, denoting the number of testcases, followed by t lines, each containing a single integer n, 1<=n<=100.
Output
For each integer n given at input, display a line with the value of n!
Example
Sample input:
41253
Sample output:
121206分析:
位数较长,可使用vector来处理。
代码:
#include <iostream>#include <vector>std::vector<int> v;void fact(int n){v.clear(); // !v.resize(200, 0);v[199] = 1;for(int i = 2; i <= n; ++i){int carry = 0;for(int j = 199; j >= 0; --j){v[j] = v[j] * i + carry;carry = v[j] / 10;v[j] %= 10;}}}int main(){int T;std::cin >> T;int n;while(T--){std::cin >> n;fact(n);int i = 0;while(v[i] == 0){++i;}for(; i < 200; ++i){std::cout << v[i];}std::cout << std::endl;}return 0;}
0 0
- CodeChef - Small factorials
- Small factorials
- codechef Small Fctorial 求阶乘值
- SPOJ - 24. Small factorials 大数相乘的运用
- factorials
- Factorials
- Factorials
- CodeChef
- CodeChef
- CodeChef
- CodeChef
- (CodeChef
- CodeChef
- CodeChef
- CodeChef
- CodeChef
- CodeChef
- CodeChef
- ios7 uitableview 上面的空白处理
- WireShark分析TCP协议
- Motivation: WebBrowser control for MWF
- Java虚拟机内存区域堆(heap)的管理
- Css hacker for ie6、ie7、firefox
- CodeChef - Small factorials
- Latex学习7: matrices
- Java JDBC下执行SQL的不同方式executeQuery/executeUpdate/execute
- 2014.09.29
- 专题四:自定义Web浏览器
- 内部类 内部类的访问 匿名内部类
- POI导入导出
- apache伪静态配置
- Eclipse Java注释模板设置详解