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寒假特辑内容请搜索靠谱客的其他文章。
发表评论 取消回复