概述
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
1987
Output
2013
Input
2013
Output
2014
周赛 CF的一道题 水题
大致题意:给定一个年份,找出距离这个年份最近的一年并且这一年的每一个数字都要不一样。。列如:1987最近的只有2013符合,,,2013找最近的就是2014了。
#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 271A所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复