首页 > 代码库 > 看个人思路吧,清晰的话就简单 CodeForces 271A - Beautiful Year

看个人思路吧,清晰的话就简单 CodeForces 271A - Beautiful Year

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 test(s)
input
1987
output
2013
input
2013
output
2014
题意就是说给你一个年份,当然是四位数的,然后要你找出比这个数大且是最先打到四位数每一个数字都不一样,可能有些同志英语不好看不懂然后小弟语文差表述也有问题,这样说吧:2013是给定的数字,比2013大且最先达到每一个数字都不一样就是2014   2    0    1    4;如今应该能明确了吧?
那咱们如今就来讲讲思路:
定义一个year作为输入,然后就是while(1)的一个循环,再定义一个flag作为标记,初值为0;
然后就是取各个数位上的数字分别赋值给a,b,c,d,然后就是一个if比較,假设不一样则flag=1;
然后推断flag是否为一,为一代表已找到符合条件的数字,则break;
这里有一点注意的是:输入year之后一定要加一,不然像2013这种是会输出2013滴!!!!!!切记,好啦,讲完!!!!!!
贴下代码:
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int main()
{
    int i,j,k;
    int t,n,m;
    int a,b,c,d;
    int year,flag;
    while(scanf("%d",&year)!=EOF)
    {
        flag=0;
        //printf("%d %d %d %d\n",a,b,c,d);
        while(1)
        {
            year++;    //千万注意这里!!!!!!千万千万千千万!!!!!!
            d=year%10;
            c=(year/10)%10;
            b=(year/100)%10;
            a=(year/1000);
            if(a!=b&&a!=c&&a!=d&&b!=c&&b!=d&&c!=d)
            {
                flag=1;
            }
            if(flag==1)
                break;

        }
        printf("%d\n",year);
    }
    return 0;
}

如有发现bug,就指出来吧!!!!!!不胜感激!!!!!!