全RE代码,求助

P1009 [NOIP1998 普及组] 阶乘之和

Problem1613end @ 2024-02-10 14:24:18


#include<iostream>
using namespace std;
int n,cap,jw,j[100000],a,zj[100000],zjw,sw;
int maxx(int qer,int per){
    if(qer>per)  return qer;
    else  return per;
}
int sr(int f){
    for(int sw=jw;sw>=1;sw--){
        j[sw]=j[sw]*f;
    }
    for(sw=1;sw<=jw;sw++){
        if(j[sw]>=10){
            j[sw+1]=j[sw+1]+j[sw]/10;
            j[sw]=j[sw]%10;
        }
    }
    if(j[jw+1]>0){
        jw++;
        if(j[jw+1]>=10){
            j[jw+1]=j[jw+1]+j[jw]/10;
            j[jw]=j[jw]%10;
            jw++;
        }
    }
}
int lj(){
    for(cap=1;cap<=maxx(jw,zjw);cap++){
        zj[cap]=zj[cap]+j[cap];
        if(zj[cap]>=10){
            zj[cap+1]++;
            zj[cap]=zj[cap]%10;
        }
    }
    zjw=maxx(zjw,jw);
    if(zj[zjw+1]>0)  zjw++;
}
int main(){
    cin>>n;
    zjw=1;
    zj[1]=1;
    jw=1;
    j[1]=1;
    if(n==1){
        cout<<1;
    }
    else{
        for(a=2;a<=n;a++){
            sr(a);
            lj();
        }
    }
    for(cap=zjw;cap>=1;cap--){
        cout<<zj[cap];
    }
    return 0;
}

by Dream_Creator @ 2024-02-10 14:36:54

@Problem1613end 后两个函数没返回值,用 void


by Problem1613end @ 2024-02-10 16:13:52

@Dream_Creator 谢谢,但改完WA#3#4,求调


|