任意给定一个整数,数出这个数中的偶数个数,奇数个数,及这个数中所包含的所有位数的总数,然后将得到的这三个数按照“偶-奇-总”的位序重新排列,得到一个新的整数。将得到的新的整数重复上面的操作,经过有限次的这样的重复操作后,最终得到123这个整数。编程计算这样的重复过程有多少次。(假设该整数最大为九位数)
输入格式:
输入一个整数。
输出格式:
输出重复的次数。
输入样例:
1234
输出样例:
在这里给出相应的输出。例如:
3
import java.util.*;
public class Main{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int cnt = fun5(n);
System.out.printf("%d",cnt);
}
public static int fun1(int n)
{
int cnt = 0;
while(n!=0)
{
if(n%10%2==0) cnt++;
n /= 10;
}
return cnt;
}
public static int fun2(int n)
{
int cnt = 0;
while(n!=0)
{
if(n%10%2!=0) cnt++;
n /= 10;
}
return cnt;
}
public static int fun3(int n)
{
int cnt = 0;
while(n!=0)
{
cnt++;
n /= 10;
}
return cnt;
}
public static int fun4(int a,int b,int c)
{
return a*100+b*10+c;
}
public static int fun5(int n)
{
int cnt = 1;
if(n==123) return 0;
while(true)
{
int a = fun1(n);
int b = fun2(n);
int c = fun3(n);
int temp = fun4(a,b,c);
if(temp!=123)
{
cnt++;
}
else if(temp==123) return cnt;
n = temp;
}
}
}