L1-033 birth (15 points)

The above is a wonderful Sina microblogging posted: "I was born in 1988, until the age of 25 did not encounter the same four digits of the year." That is, until 2013 to reach "4 digits are not the same." requirements. This question you upon request, automatically populate "I was born in yyears until xthe age of encounters nnumbers are not the same year," this sentence.

Input formats:

In the year of birth given input row ynumber and the different numbers of the target year n, which yis among [1, 3000], nit may be a 2, or 3, or 4. Note to less than 4 years of zero padding in front, for example, the year 1 is considered to be 0001, there were two different digits 0 and 1.

Output formats:

Input based on the output xand can meet the requirements of the year. Between numbers separated by a space, the line from beginning to end may not have the extra space. Year Yaoan four outputs. Note: The so-called " nnumbers are not the same" means different number happens to be none. The "2013" is considered to meet the "four-digit number is different" conditions, and are not considered two or three digits different conditions.

Sample Input 1:

1988 4
 

Output Sample 1:

25 2013
 

Sample Input 2:

1 2
 

Output Sample 2:

0 0001





/**
 * 
 */
package com.xingbing.tianti;

import java.util.HashSet;
import java.util.Scanner;
java.util.Set amount;

/**
 * @Author Xing Bing
 * @data
 * @Description this relatively simple problem solving is to use a collection set, each time adding to each digit of the same size and resolution of the specified n set collection if the collection set, the output or input plus years One. Pay special attention to this problem 3000, if the outer loop to the limit of 3000 then 
3000 will complain this point */ public class L1033 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int year = in.nextInt(); int n = in.nextInt(); Set<Integer> set = new HashSet<Integer>(); int total = 0; int i; for(i=year;i<=4000;i++){ int t = i; for(int j=0;j<4;j++){ set.add(t%10); t/=10; } if(set.size()==n){ break; } total++; set.clear(); } System.out.print(total+" "); System.out.printf("%04d", i); } }

  

Guess you like

Origin www.cnblogs.com/xuesujun/p/12216063.html