75pts,求调

P1009 [NOIP1998 普及组] 阶乘之和

ivan11 @ 2024-05-01 11:20:06


include<iostream>
#include<cstring>
#include<string>
using namespace std;
const int len = 5005;
struct big
{
    long long l;
    long long a[len];

    void clear()
    {
        for(int i=l;i>=2;--i)
        {
            if(!a[i]) -- l;
            else break ;
        }
        return ;
    }

    void in()
    {
        string s;
        cin>>s;
        l=s.length();
        for(int i=1;i<=l;++i)
        {
            a[i] = (s[l-i] & 15);
        }
        return ;
    }

    void out()
    {
        clear();
        for(int i=l;i>=1;--i)
        {
            cout<<a[i];
        }
        cout<<'\n';
        return ;
    }

    big operator + (big b)const 
    {
        big c;
        memset(c.a,0,sizeof(c.a));
        c.l = max(l,b.l) + 1;
        for(int i=1;i<=c.l;++i)
        {
            c.a[i] += a[i] + b.a[i];
            c.a[i+1] = c.a[i] / 10;
            c.a[i] %= 10;
        }
        return c;
    }

    big operator * (int b)const
    {
        big c;
        memset(c.a,0,sizeof(c.a));
        c.l = l + 1;
        for(int i=1;i<=l;++i)
        {
            c.a[i] += a[i] * b;
        }
        for(int i=1;i<=c.l;++i)
        {
            c.a[i+1] += c.a[i] / 10;
            c.a[i] %= 10;
        }
        return c;
    }
}num,ans;
long long n;

int main()
{
    cin>>n;
    memset(num.a,0,sizeof(num.a));
    memset(ans.a,0,sizeof(ans.a));
    num.l=1;
    num.a[1]=1;
    ans.l=1;
    ans.a[1]=1;
    for(int i=2;i<=n;++i)
    {
        num = num * i;
        ans = ans + num;
    }
    ans.out();
    return 0;
}

by MuYuMC @ 2024-06-07 20:56:29

你这有些复杂啊

#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <iomanip>
using namespace std;
int A[2000]; 
int B[2000];
int sum[99999];
void cheng()
{
    int i;
    for(i = 1;i <= A[0];i++)
    {
        A[i] = A[i] * B[i]; 
    }
    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,k;
    string s1,s2;
    cin >> s1 >> s2;
    A[0] = s1.size();
    B[0] = s2.size(); 
    for(i = 1;i <= s1.size();i++)
    {
        A[i] = s1[A[0] - i] - '0';
    }
    for(i = 1;i <= s2.size();i++)
    {
        B[i] = s2[B[0] - i] - '0';
    }
    cheng();
    for(i = A[0];i >= 1;i--)
    {
        cout << A[i];
    }
    return 0;
} 

|