acm寒假特辑 1月17日 CodeForces

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再寻找,把每个数字提取出来进行判断,输出。

#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;
}
原文地址:https://www.cnblogs.com/gidear/p/10433286.html