Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 37 Solved: 35
[Submit][Status][Web Board]Description
计算一个整数的阿尔法乘积。对于一个整数x来说,它的阿尔法乘积是这样来计算的:如果x是一个个位数,那么它的阿尔法乘积就是它本身;否则的话,x的阿 尔法乘积就等于它的各位非0的数字相乘所得到的那个整数的阿尔法乘积。例如:4018224312的阿尔法乘积等于8,它是按照以下的步骤来计算的:
4018224312 → 4*1*8*2*2*4*3*1*2 → 3072 → 3*7*2 → 42 → 4*2 → 8
编写一个程序,输入一个正整数(该整数不会超过6,000,000),输出它的阿尔法乘积。
Input
输入只有一行,即一个正整数。
Output
输出相应的阿尔法乘积。
Sample Input
4018224312
Sample Output
8
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn = 1e4 + 5;
int main()
{
int n;
char a[10];
scanf("%d",&n);
int flag = 0;
int sum;
while(flag != 1)
{
int tmp = 0;
sum = 1;
while(n != 0)
{
a[tmp ++] = n % 10;
n /= 10;
}
for(int i = 0; i < tmp;i++)
{
if(a[i] != 0)
sum *= a[i];
}
n = sum;
if(tmp == 1)
flag = 1;
}
cout<<sum<<endl;
return 0;
}