Java implementation of the Blue Bridge Cup analog increasing number

Problem Description
  A positive integer digit if not more than any one digit to the right adjacent is called increasing number one digit, for example, 1135 is a digital incremental number, rather than a 1024 digit number is incremented.
  Given a positive integer n, we wonder how many digits in increasing the number of integers from 1 to n?
Input format
  of the first line of the input contains an integer n.
Output format
  output line contains an integer that represents the answer.
Input Sample
30
Sample Output
26
reviews agreement with the size of cases
  for evaluation by 40% in Example, 1 <= n <= 1000 .
  For evaluation by 80% in Example, 1 <= n <= 100000 .
  For the evaluation all use cases, 1 <= n <= 1000000 .

package 第十三次模拟;

import java.util.Scanner;

public class Demo7递增数 {
	public static int n=0,count=0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		sc.close();
		f(0,1);
		System.out.println(count-1);
	}
	public static  void f(int num,int temp){
		if(num>n){
			return;
		}
		else{
//			System.out.println(num);
			count++;
		}
		for (int i = temp; i <10; i++) {
			f(num*10+i,i);
		}
	}
	

}

Released 1472 original articles · won praise 10000 + · views 1.76 million +

Guess you like

Origin blog.csdn.net/a1439775520/article/details/104750295