Tsinsen A1115 高精度计算

http://oj.tsinsen.com/A1115

分析:A过去就好了..

代码:

#include "bits/stdc++.h"
using namespace std;

class BigInt {
public:
    int num[100];
    BigInt() { memset(num, 0, sizeof(num)); }
    void Multiply (int n) {
        int t = 0;
        for (int i = 0; i < 100; ++i) {
            num[i] = (t + n * num[i]);
            t = num[i] / 10; num[i] %= 10;
        }
    }
    void Plus (const BigInt & u) {
        int t = 0;
        for (int i = 0; i < 100; ++i) {
            num[i] += (t + u.num[i]);
            t = num[i] / 10; num[i] %= 10;
        }
    }
};

int main() {
    int n; scanf("%d", &n);
    BigInt Res;
    for (int i = 1; i <= n; ++i) {
        BigInt a; a.num[0] = 1;
        for (int k = 1; k <= i; ++k)
            a.Multiply(k);
        Res.Plus(a);
    }
    int p = 99; while (Res.num[p] <= 0) --p;
    while (p >= 0) { printf("%d", Res.num[p--]); }
    return 0;
}

你可能感兴趣的:(ACM-01)