It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
The single line contains integer y (1000?≤?y?≤?9000) — the year number.
Print a single integer — the minimum year number that is strictly larger than y and all it‘s digits are distinct. It is guaranteed that the answer exists.
1987
2013
2013
2014
#include<stdio.h> #include<string.h> #include<iostream> using namespace std; int main() { int i,j,k; int t,n,m; int a,b,c,d; int year,flag; while(scanf("%d",&year)!=EOF) { flag=0; //printf("%d %d %d %d\n",a,b,c,d); while(1) { year++; //千万注意这里!!!!!!千万千万千千万!!!!!! d=year%10; c=(year/10)%10; b=(year/100)%10; a=(year/1000); if(a!=b&&a!=c&&a!=d&&b!=c&&b!=d&&c!=d) { flag=1; } if(flag==1) break; } printf("%d\n",year); } return 0; }
如有发现bug,就指出来吧!!!!!!不胜感激!!!!!!