写了一上午,,,哦哦哦!
http://acm.bjfu.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1005
通过字符串进行N的阶乘的运算,从0位置开始,若有进位,将答案长度加上1。并且对后面的按照进位进行赋值。
# include <stdio.h>
# include <memory.h>
# include <string>
char
a[100000];
void
jiecheng(
int
n)
{
memset
(a,
'0'
,
sizeof
(a));
if
(n==0)
printf
(
"1\n"
);
else
{
int
i;
int
temp=0,cin=0,t=0,count=1;
int
m=0;
a[0]=
'1'
;
for
(i=1;i<n+1;i++)
{
for
(m=0;m<count;m++)
{
temp=(a[m]-
'0'
)*i+cin;
a[m]=temp%10+
'0'
;
cin=temp/10;
}
while
(cin)
{
temp=cin%10;
a[m]=temp+
'0'
;
cin=cin/10;
m++;
count++;
}
}
// printf("count is %d\n",count);
// printf("cin is %d\n",cin);
for
(i=m-1;i>=0;i--)
printf
(
"%c"
,a[i]);
printf
(
"\n"
);
}
}
int
main ()
{
int
n;
while
(
scanf
(
"%d"
,&n)!=EOF)
{
jiecheng(n);
}
return
0;
}