概述
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;
}
最后
以上就是忧心红酒为你收集整理的acm寒假特辑 1月17日 CodeForces - 271A(基础)C - 3 CodeForces - 271A的全部内容,希望文章能够帮你解决acm寒假特辑 1月17日 CodeForces - 271A(基础)C - 3 CodeForces - 271A所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复