Algorithm Training Alpha Product time limit: 1.0s memory limit: 512.0MBThe problem description calculates the alpha product of an integer. For an integer x, its alpha product is calculated as this: if X is a single digit, then its alpha product is itself; otherwise, the Alpha product of x is equal to the alpha product of the integer that is obtained by multiplying the number of its members by 0. For example: The alpha product of 4018224312 equals 8, which is calculated by following these steps:
4018224312→4*1*8*2*2*4*3*1*2→3072→3*7*2→42→4*2→8
Write a program, enter a positive integer (the integer will not exceed 6,000,000), and output its alpha product.
Input format: Enter only one line, that is, a positive integer.
Output format: Outputs the corresponding alpha product.
Input and Output sample sample input 4018224312 Sample Output 8 Author Comments: This problem originally thought relatively simple, later only want to use the character array to hold the input number, and then through the traversal plus judgment to operate, the process thought of the return to do, the export for n<10.
1#include <stdio.h>2 Long LongALong LongN) {3 if(n<Ten){//Recursive exit4 returnN;5}Else{6 Long LongJi=1;7 while(n!=0){8 if(n%Ten!=0){//if it cannot be divisible by 10, the remainder is multiplied into the result and the n is divided by the 10 operation.9ji*=n%Ten;TenN/=Ten; One}Else//if it is divisible by 10, the result will be the same, so divide by the 10 operation AN/=Ten; - } - returnA (JI); the } - } - Main () { - Long Longx; +scanf"%lld",&x); -printf"%lld", A (x)); +}
C language · Alpha Product