Description
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.
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 Input
Input
复制代码
11987
Output
复制代码
12013
Input
复制代码
12013
Output
复制代码
12014
周赛 CF的一道题 水题
大致题意:给定一个年份,找出距离这个年份最近的一年并且这一年的每一个数字都要不一样。。列如:1987最近的只有2013符合,,,2013找最近的就是2014了。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36#include <iostream> using namespace std; int Year(int Y) { int year[10] = {0};//保存0到9的十个数字,并归零 int qq = 1; int num = 0; for (int j = 0; j < 4; j++)//根据题意1000~9000循环四次 { num = ( Y / qq ) % 10;//找出四个数字 if (year[num] == 0) { year[num] = 1;//标记,避免相同 } else return 0; qq = qq * 10;//每次乘10 } return 1; } int main() { int Y; while (cin>>Y) { for (int i = 1;i < 9000; i++) { if (Year(Y+i))//每次加i,最近 { cout << Y+i << endl; break; } } } return 0; }
最后
以上就是幸福鲜花最近收集整理的关于CodeForces 271A的全部内容,更多相关CodeForces内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复