Vigorous_Z @ 2024-02-18 15:11:53
25分C语言代码,第二个测试点已经下载并在本机(使用DevC++)测试过且答案正确,但是传到洛谷还是只有第一个测试点过了wwwww还请大佬们看看是哪里出了问题 (代码是分成两次写的并且时间间隔较长,所以代码很臃肿请见谅qwq)下面是代码
#include<stdio.h>
#include<string.h>
void addhigh(char a[],char b[], char res[])
{
int m[1000], n[1000];
for (int i = 0; i < 1000; i++)//初始化数组
m[i] = 0, n[i] = 0;
for (int i = strlen(a) - 1,j = 0;i >= 0;i--,j++)//将字符串的数字倒序录入数组
m[i] = a[j] - '0';
for (int i = strlen(b) - 1,j = 0;i >= 0;i--,j++)
n[i] = b[j] - '0';
int maxlen = strlen(a)>strlen(b)?strlen(a):strlen(b);//求最大长度
for (int i = 0; i < maxlen; i++)//运算核心
{
m[i] = m[i] + n[i];
if (m[i] >= 10)
{
m[i+1] += m[i] / 10;
m[i] = m[i] % 10;
}
}
if (m[maxlen] != 0)
maxlen++;
for (int i = maxlen - 1,j = 0; i >= 0; i--,j++)
res[j] = m[i] + '0';
res[maxlen] = '\0';
}
void multhigh(char a[],char b[], char res[])
{
int m[1000], n[1000], l;
char res1[1000] = {0};
for (int i = 0; i < 1000; i++)//初始化数组
m[i] = 0, n[i] = 0;
for (int i = strlen(a) - 1,j = 0;i >= 0;i--,j++)//将字符串的数字倒序录入数组
m[i] = a[j] - '0';
for (int i = strlen(b) - 1,j = 0;i >= 0;i--,j++)
n[i] = b[j] - '0';
l = strlen(a) + strlen(b) - 1;
for (int i = 0; i < (int)strlen(a); i++)//运算核心
for (int j = 0; j < (int)strlen(b); j++){
res1[i+j] =res1[i+j] + m[i] * n[j];
for (;;){
if (res1[i+j] >= 10){
res1[i+j+1]++;
res1[i+j] -= 10;
}
else break;
}
}
if (res1[l] != 0)
l++;
for (int i = l - 1,j = 0; i >= 0; i--,j++)
res[j] = res1[i]+'0';
}
void copy (char a[], char b[]){
memset(a,0,sizeof(*a));
for (int i = 0; i < (int)strlen(b); i++){
a[i] = b[i];
}
return ;
}
void reverse (char a[]){
char b[1000];
for (int i = 0; i < (int)strlen(a); i++){
b[i] = a[strlen(a)-1-i];
}
copy(a,b);
return ;
}
int main()
{
char ans[1000] = {0},step1[1000] = {0},step2[1000] = {0},step3[1000] = {0},temp[1000] = {0},zero[1000] = {0};
int n, k;
scanf("%d",&n);
step1[0] = '1';
for (; n>0; n--){
k = n;
for(; k>0; k--){
int j = k, i = 0;
for (;;){
if (j > 0){
step2[i] = j%10 + '0';
j = j/10;
i++;
}
else break;
}
reverse(step2);
multhigh(step1,step2,step3);
copy(step1,step3);
memset(step2,0,sizeof(step2));
}
addhigh(ans,step1,temp);
copy(ans,temp);
memset(step1,0,sizeof(step1));
memset(step3,0,sizeof(step3));
step1[0] = '1';
}
printf("%s",ans);
return 0;
}
by 09rxq @ 2024-03-01 13:24:44
using namespace std;
int main()
{
int i,a[1005]={0},b[1005]={0},n,j;
scanf("%d", &n);
a[0]=b[0]=1;
for (int i=2;i<=n;i++)
{
for (j=0;j<101;j++)
b[j]*=i;
for (j=0;j<101;j++)
if (b[j]>9)
{
b[j+1] += b[j]/10;
b[j]%=10;
}
for (j=0;j<100;j++)
{
a[j]+=b[j];
if (a[j]>9)
{
a[j+1] += a[j]/10;
a[j]%=10;
}
}
}
for (i=100;i>=0&&a[i]==0;i--);
for (j=i;j>=0;j--)
printf("%d", a[j]);
return 0;
}