The above is a strange post on Sina Weibo: "I was born in 1988, and I didn't encounter 4 years with different numbers until I was 25 years old." That is to say, it was not until 2013 that "4 numbers are different". requirements. In this question, please fill in the sentence "I was born in year y, and I didn't encounter n years with different numbers until the age of x" according to the requirements.
Input format:
The input gives the number n of different digits in the birth year y and the target year in one line, where y is between [1, 3000], and n can be 2, or 3, or 4. Note that the year with less than 4 digits should be filled with zeros in front. For example, the year 1 AD is considered to be 0001, and there are 2 different numbers 0 and 1.
Output format:
According to the input, output x and the year that can meet the requirements. The numbers are separated by 1 space, and there must be no extra spaces at the beginning and end of the line. The year is to be output in 4 digits. Note: The so-called "n numbers are not the same" means that there are exactly n different numbers. For example, "2013" is considered to satisfy the condition that "4 digits are different", but not to satisfy the condition that 2 or 3 digits are different.
Input sample 1:1988 4Sample output 1:
25 2013Input sample 2:
1 2Sample output 2:
0 0001
Code:
#include<stdio.h> #include<map> using namespace std; intmain() { int i,j,n,m,k,t; scanf("%d %d",&n,&m); for(i=n;;i++) { map<int,int> Map; char str[5]; sprintf(str,"%04d",i); Map[str[0]-'0']=1; Map[str[1]-'0']=1; Map[str[2]-'0']=1; Map[str[3]-'0']=1; if(Map.size()==m) { printf("%d %04d",i-n,i); break; } } return 0; }