A. Beautiful Year
time limit per test
2 secondsmemory limit per test
256 megabytesinput
standard inputoutput
standard outputIt 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.
Input
The single line contains integer y (1000 ≤ y ≤ 9000) — the year number.
Output
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.
Sample test(s)
input
1987
output
2013
input
2013
output
2014
1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <cstring> 5 int judge(int n) 6 { 7 int a[10]; 8 memset(a, 0, sizeof(a)); 9 int k = 1; 10 for (int i = 0; i < 4; ++i) 11 { 12 if (a[(n/k)%10] == 0) 13 { 14 a[(n/k)%10] = 1; 15 } 16 else return 0; 17 k *= 10; 18 } 19 return 1; 20 } 21 int main(void) 22 { 23 int y; 24 while (~scanf("%d", &y)) 25 { 26 for (int i = 1; ; ++i) 27 { 28 if (judge(y+i)) 29 { 30 printf("%d\n", y+i); break; 31 } 32 } 33 } 34 35 return 0; 36 }
天下没有水题……
先看清题目意思,然后认真快速敲代码就可以了。
意思是给出一个年份,求出严格比它大的,并且这个年份的四个数字互不相同的最小年份,年份的范围是[1000, 9000]