求助,不知错因的孩纸。。。
查看原帖
求助,不知错因的孩纸。。。
419652
MOXCOOT楼主2021/3/7 18:46
#include <iostream>
#include <vector>
#include <cstring>
#define NUM 1010
using namespace std;
int n;
int find(int* a, int x) {                          //找到a[]中x的个数
    int cnt = 0;
    bool flag = 0;
    for (int i = NUM - 1; i>=0; i--) {
        if (a[i])flag = 1;
        if (a[i] == x && flag == 1)cnt++;
    }
    return cnt;
}
void multi(int* a, int x) {                      //a[]*x函数
    int last = 0;
    for (int i = 0; i < NUM; i++) {
        a[i] = a[i] * x + last;
        last = a[i] / 10;
        a[i] %= 10;
    }
}
int nub(int x, int y) {                        
    int a[NUM] = { 0 };
    a[0] = 1;
    for (int i = 1; i <= x; i++) {
        multi(a, i);
    }
    return find(a, y);
}
int main() {
    cin >> n;
    int t[12];
    int tt = 0;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        t[i] = nub(x, y);
        tt++;
    }
    for (int i = 0; i < tt; i++) {
        cout << t[i] << endl;
    }
}
2021/3/7 18:46
加载中...