稻花香里说丰年,听取WA声一片, 求调.

P1591 阶乘数码

furina_yyds @ 2023-08-25 14:57:47

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int ans[1005], a[1005], n, j[1005];
void s2BIG(string s, int a[]){
    int al = s.size();
    for(int i = 1; i <= al; i++){
        a[i] = a[al - i] - '0';
    }
    a[0] = al;
}
int statistics(int a[], int b){
    int al = a[0], ans = 0;
    for(int i = 1;i <= al;i++){
        if(a[i] == b){
            ans++;
        }
    }
    return ans;
}
void printBIG(int a[]){
    int al = a[0];
    for(int i = al; i >= 1; i--){
        printf("%d", a[i]);
    }
}
void mulBIG(int a[], int b, int c[]){
    int al = a[0];
    int bl = al;
    int u = 0;
    for(int i = 1; i <= bl; i++){
        int t = a[i] * b + u;
        c[i] = t % 10;
        u = t / 10;
    }
    while(u > 0){
        bl++;
        c[bl] = u % 10;
        u /= 10;
    }
    c[0] = bl;
}
void addBIG(int a[], int b[], int c[]){
    int al = a[0], bl = b[0];
    int cl = max(al, bl);
    int u = 0;
    for(int i = 1; i <= cl; i++){
        int t = u;
        if(i <= al)t += a[i];
        if(i <= bl)t += b[i];
        c[i] = t % 10;
        u = t / 10;
    }
    if(u > 0){
        cl++;
        c[cl] = u;
    }
    c[0] = cl;
}
int main() {
    int t;
    scanf("%d", &t);
    for(int i = 1; i <= t; i++)
    {
        int b, x, cnt;
        memset(a, 0, sizeof(a));
        a[0] = 1;
        a[1] = 1;
        scanf("%d%d", &b, &x);
        for(int i = 1; i <= b; i++){
            mulBIG(a, i, j);
            memcpy(a, j, sizeof(j));
        }
        printf("%d\n", statistics(a, x));
    }
    return 0;
}

by songlll @ 2023-09-01 18:59:35

addBIG这个函数你也没有用啊?


by songlll @ 2023-09-02 17:56:22

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int a[10005], j[10005];
int statistics(int a[], int b){
    int al = a[0], ans = 0;
    for(int i = 1;i <= al;i++){
        if(a[i] == b){
            ans++;
        }
    }
    return ans;
}
void mulBIG(int a[], int b){
    int bl = a[0];
    int u = 0;
    for(int i = 1; i <= bl; i++){
        int t = a[i] * b + u;
        a[i] = t % 10;
        u = t / 10;
    }
    while(u > 0){
        bl++;
        a[bl] = u % 10;
        u /= 10;
    }
    a[0] = bl;
}
int main() {
    int t;
    scanf("%d", &t);
    for(int i = 1; i <= t; i++)
    {
        char x[100]; 
        int b, cnt;
        memset(a, 0, sizeof(a));
        a[0] = 1;
        a[1] = 1;
        scanf("%d%s", &b, &x);
        for(int i = 2; i <= b; i++){
            mulBIG(a, i);
        }   
        printf("%d\n", statistics(a, x[0]-48));
    }
    return 0;
}

|