游戏从一个整数S开始,只要它的位数多于1,就计算它各位的乘积,并且不断重复这个过程。比如:我们从95开始,9 × 5 = 45,45不是1位数,继续4 × 5 = 20.继续2 × 0 = 0.至此只有1位数,结束。
再比如:如果从396开始
3 × 9 × 6 = 162
1 × 6 × 2 = 12
1 × 2 = 2
最后得到2。
Input
每行开始1个整数,表示起始值。最后以0结束。
Output
游戏从开始到结束的序列,从起始值开始。
Sample Input
95
396
28
4
40
0
Sample Output
95 45 20 0
396 162 12 2
28 16 6
4
40 0
#include <iostream>
using namespace std;
int main()
{
int s,c,a=1,b,i,n;
while(cin>>s)
{
if(s!=0)
{
n=s/10;
b=s;
if(n==0)
cout<<s<<endl;
else
{ cout<<s<<' ';
while(n!=0)
{ a=1;
for(i=0;n!=0;i++)
{
n=s/10;
s=n;
}//几位数;
while(i!=0)
{
c=b%10;
a=a*c;
b=b/10;
i--;
}
n=a/10;
b=s=a;
if(a/10!=0)
cout<<a<<' ';
else
cout<<a<<endl;
}
}
}
else
break;
}
return 0;
}