2022-09-05

P1009 [NOIP1998 普及组] 阶乘之和

Tom_catLLL @ 2022-11-03 17:11:25

#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;

int main()
{
    int n, a[1001] = { 0 }, b[1001] = { 0 },i,j;
    cin >> n;
    a[0] = b[0] = 1;
    for (i = 2; i <= n; i++)
    {
        for (j = 0; j < 100; j++)
            a[j] *= i;
        for (j = 0; j < 100; j++)
        {
            if (a[j] > 9)
            {
                a[j + 1] += a[j] / 10;
                a[j] %= 10;
            }
        }
        for (j= 0; j < 100; j++)
        {
            b[j] += a[j];
            if (b[j] > 9)
            {
                b[j + 1] = b[j] / 10;
                b[j] %= 10;
            }
        }
    }
    for (i=100; i>=0 && b[i]==0;i--);
    for (j=i; j >= 0; j--)
        cout << b[j];
    system("pause");
    return 0;
}

by xiaohaoaibiancheng66 @ 2022-11-03 17:14:08

system("pause")

是个啥玩意


by CH_mengxiang @ 2022-11-03 17:38:36

@xiaohaoaibiancheng66 这人估计用的老版本,以前需要用这句话暂停的


by WA_sir @ 2022-11-03 18:21:29

@Tom_catLLL 你不都过了吗?


by Tom_catLLL @ 2022-11-03 18:42:01

@WA_sir 没有,我发的这串没过


by Tom_catLLL @ 2022-11-03 18:42:27

@xiaohaoaibiancheng66 教程用的,保持好习惯


by xiaohaoaibiancheng66 @ 2022-11-03 20:36:52

@Tom_catLLL 我很怀疑这是不是好习惯


by Tom_catLLL @ 2022-11-05 21:45:50

@xiaohaoaibiancheng66 好吧?


by xiaohaoaibiancheng66 @ 2022-11-05 21:56:41

@Tom_catLLL 我很不理解为什么要这么做


by Tom_catLLL @ 2022-11-06 23:17:54

@xiaohaoaibiancheng66 我是跟着c++教程学的,教程有这一行代码的。我估计学校的老机子上面就是老板的vs,所以多写一点没毛病。是吧,哈哈


by xiaohaoaibiancheng66 @ 2022-11-07 17:39:32

@Tom_catLLL 有毛病


| 下一页