我是靠谱客的博主 忧心红酒,这篇文章主要介绍acm寒假特辑 1月17日 CodeForces - 271A(基础)C - 3 CodeForces - 271A,现在分享给大家,希望可以做个参考。

C - 3 CodeForces - 271A

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.

Examples
Input
1987
Output
2013
Input
2013
Output
2014

题目大意:找出指定年份的下一个年份中每个数字不同的年份,(不知各位能否看懂)。
思路:先+1再寻找,把每个数字提取出来进行判断,输出。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<iostream> using namespace std; int main() { int y, n, x = 1, a, b, c, d; cin >> y; n = y; for (int i = 1;x; i++) { n = y + i; a = n / 1000; b = n % 1000 / 100; c = n % 100 / 10; d = n % 10; if (a == b || a == c || a == d || b == c || b == d || c == d) x = 1; else x = 0; } cout << n << endl; return 0; }

最后

以上就是忧心红酒最近收集整理的关于acm寒假特辑 1月17日 CodeForces - 271A(基础)C - 3 CodeForces - 271A的全部内容,更多相关acm寒假特辑内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(50)

评论列表共有 0 条评论

立即
投稿
返回
顶部