Persistence(模拟)

Persistence(模拟)

时间限制: 1 Sec  内存限制: 128 MB
 

题目描述

Consider the series of numbers where each term is the product  of the decimal digits of the previous term. Eventually the term will be reduced to a single digit.

For example start with 679:

The  number  of  steps  this  takes  is  called  the  Persistence  of  a  number.  Thus,  the persistence  of  679  is  5,  since  that’s  number  of  steps  it  took  to  get  to  a  single  digit number.

输入

Each input will consist of a single test case. Note that your program may be run multiple times on different inputs. The input will consist of a single line, with a positive number of up to 9 decimal digits with no leading zeros. 

输出

For  each  test  case,  output  a  single  integer,  representing  the  persistence  of  the  input number;  that is, the number of steps necessary to reduce it to a single digit.  

样例输入 

5

样例输出 

0

思路:模拟,水题,附上AC代码

#include<bits/stdc++.h>
using namespace std;

int main()
{
	int num = 0;
	int cnt = 0;
	cin >> num;
	if(num < 10)
	{
		cout << 0 << endl;
		return 0;
	}
	else
	{
		while(num >= 10)
		{
			int temp = 1;
			do
			{
				temp *= num % 10;
			}while(num /= 10);
			cnt++;
			num = temp;
		}
		
	}
	
	cout << cnt << endl;
	
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值