top1编程
← 返回题目
题解

【基础】阿尔法乘积

1 条题解

  • 0
    @ 2026-7-29 0:17:41
    #include <iostream>
    using namespace std;
    
    int alphaProduct(int n) {
        // 当 n 是个位数时,直接返回
        if (n < 10) {
            return n;
        }
    
        int product = 1;
        while (n > 0) {
            int digit = n % 10;
            if (digit != 0) {  // 只处理非零数字
                product *= digit;
            }
            n /= 10;
        }
    
        // 递归调用,继续求 product 的阿尔法乘积
        return alphaProduct(product);
    }
    
    int main() {
        int x;
        cin >> x;
    
        cout << alphaProduct(x) << endl;
    
        return 0;
    }
    
    • 1