Yangshuhao123 @ 2024-08-31 22:02:10
#include<bits/stdc++.h>
using namespace std;
string multiplication(string s1,string s2){
string ans;
int i,j,a[1000],b[1000],c[1000];
if(s1=="0"||s2=="0")
cout<<0;
for(i=0;i<s1.size();i++)
a[s1.size()-1-i]=s1[i]-48;
for(i=0;i<s2.size();i++)
b[s2.size()-1-i]=s2[i]-48;
int l=s1.size()+s2.size();
for(i=0;i<s1.size();i++)
for(j=0;j<s2.size();j++)
c[i+j]+=a[i]*b[j];
for(i=0;i<l;i++)
if(c[i]>9){
c[i+1]+=c[i]/10;
c[i]%=10;
}
for(i=l-1;i>=0;i--){
if(c[i]==0)
l--;
else
break;
}
for(i=l-1;i>=0;i--)
ans=ans+char(c[i]+48);
return ans;
}
string addition(string s1,string s2){
string ans;
int i,a[1000],b[1000],c[1000];
for(i=0;i<s1.size();i++)
a[s1.size()-1-i]=s1[i]-48;
for(i=0;i<s2.size();i++)
b[s2.size()-1-i]=s2[i]-48;
int l=max(s1.size(),s2.size());
for(i=0;i<l;i++)
c[i]=a[i]+b[i];
for(i=0;i<l;i++)
if(c[i]>9){
c[i]-=10;
c[i+1]++;
}
if(c[l]==0)
l--;
for(i=l-1;i>=0;i--)
ans=ans+char(c[i]+48);
return ans;
}
string int_to_str(short int n){
string ans;
if(n>9)
ans=char(n/10+48)+char(n%10+48);
else
ans=char(n+48);
return ans;
}
int main(){
short int i,j,n;
string num,ans;
cin>>n;
for(i=1;i<=n;i++){
for(j=1;j<=i;j++)
num=multiplication(num,int_to_str(j));
ans=addition(ans,num);
}
cout<<ans;
return 0;
}
by MuYuMC @ 2024-08-31 22:05:02
额,你这代码属实有点。。 看看我的吧
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#define ll long long
using namespace std;
int A[100000];
int B[100000];
void jia()
{
int i,h;
h = max(A[0],B[0]);
for(i = 1;i <= h;i++)
{
B[i] += A[i];
B[i + 1] += B[i] / 10;
B[i] = B[i] % 10;
}
if(B[i] != 0)
{
B[0] = h + 1;
}
else
{
B[0] = h;
}
}
void cheng(int x)
{
int i;
for(i = 1;i <= A[0];i++)
{
A[i] *= x;
}
for(i = 1;i <= A[0];i++)
{
A[i + 1] += A[i] / 10;
A[i] = A[i] % 10;
}
while(A[i] != 0)
{
A[i + 1] += A[i] / 10;
A[i] = A[i] % 10;
A[0]++;
i++;
}
}
int main()
{
int n,i;
cin >> n;
A[0] = 1;
A[1] = 1;
B[0] = 1;
for(i = 1;i <= n;i++)
{
cheng(i);
jia();
}
for(i = B[0];i >= 1;i--)
{
cout << B[i];
}
return 0;
}
by TimADE @ 2024-08-31 22:05:08
@Yangshuhao123
#include<iostream>
#include<cstdio>
using namespace std;
int n,a[101]={0},s[101]={0};
void change(int x)
{
int g=0;
for(int i=100;i>=0;i--)
{
a[i]=a[i]*x+g;
g=a[i]/10;
a[i]=a[i]%10;
}
}
void qh()
{
int g=0;
for(int i=100;i>=0;i--)
{
s[i]=s[i]+a[i]+g;
g=s[i]/10;
s[i]=s[i]%10;
}
}
void sc()
{
int w;
for(int i=0;i<=100;i++)
{
if(s[i]!=0)
{
w=i;
break;
}
}
for(int i=w;i<=100;i++)
printf("%d",s[i]);
}
int main()
{
scanf("%d",&n);
s[100]=a[100]=1;
for(int i=2;i<=n;i++)
{
change(i);
qh();
}
sc();
return 0;
}
by MuYuMC @ 2024-08-31 22:05:17
求关
by DESTRUCTION_WA @ 2024-09-23 11:53:50
@MuYuMC 你前面那\~\~\~\~么长的#include
不能直接#include <bits/stdc++.h>
万能头吗?
by MuYuMC @ 2024-09-23 12:06:20
@bored_frank 小贴士:比赛时最好不要用,要不然容易编译错误
by DESTRUCTION_WA @ 2024-09-23 12:21:08
@MuYuMC ……………………又收获了一个冷知识
by MuYuMC @ 2024-09-23 12:43:49
@bored_frank 比如y1是关键字