2 条题解
-
0Guest
-
2
QAQ刚才不小心上传的是昨天的大份,这才是能过的题解(ps:字符串真的容易爆所以换了数组结构体)
#include<bits/stdc++.h> using namespace std; const int maxn=50500; struct node{ int f[maxn],len; node(){ memset(f,0,sizeof(f)); len=1; } node operator=(const string&p){ len=p.size(); for(int i=0;i<len;i++) f[len-i-1]=p[i]-'0'; return *this; }//字符串赋值给node的重载 node operator=(int n){ if(n==0)return*this; int i=0; while(n){ f[i++]=n%10; n/=10; } len=i; return*this; }//整形赋值给node的重载 node operator*(const node&p){ node tmp; int y=0; tmp.len=len+p.len; for(int i=0;i<len;i++) for(int j=0;j<p.len;j++) tmp.f[i+j]+=f[i]*p.f[j]; for(int i=0;i<tmp.len;i++){ tmp.f[i+1]+=tmp.f[i]/10; tmp.f[i]%=10; } if(!tmp.f[tmp.len-1])tmp.len--; return tmp; }//重载乘号 };//,结构体别忘分号,一个分号找我半天(生气) istream&operator>>(istream&in,node&p){ string s; in>>s; p=s; return in; }//重载输入 ostream&operator<<(ostream&out,const node&p){ for(int i=p.len-1;i>=0;i--) out<<p.f[i]; return out; }//重载输出 int main(){ int n; cin>>n; node a,t; a=1; for(int i=1;i<=n;i++){ t=i; a=a*t; }//“核心” cout<<a<<endl; return 0; }
-
0
#include<bits/stdc++.h> using namespace std; int a[1000000]; int main() { int n; cin>>n; int w=0,l=2;//l储存长度 a[1]=1; for(int i=1;i<=n;i++) { for(int j=1;j<l;j++)//逐位相乘 { a[j]=a[j]*i+w; w=a[j]/10;//设置进位 a[j]=a[j]%10;//储存当前位数 } while(w>0)//处理进位 { a[l]=w%10; l++; w/=10; } } for(int i=l-1;i>=1;i--)//倒序输出 { cout<<a[i]; } return 0; }
- 1
信息
- ID
- 200
- 时间
- 3000ms
- 内存
- 256MiB
- 难度
- 8
- 标签
- 递交数
- 20
- 已通过
- 7
- 上传者