CodeForces 271 A.Beautiful Year(水~)

来源:互联网 发布:fc存储网络 编辑:程序博客网 时间:2024/06/03 22:30

Description

给出一整数n,求大于n的数字中满足每一位都不相同的最小数字

Input

一个正整数n(1000n9000)

Output

输出大于n的最小的满足条件的数字

Sample Input

1987

Sample Output

2013

Solution

水题,从n+1开始一个个枚举判断是否合法即可

Code

#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<queue>#include<map>#include<set>#include<ctime>using namespace std;typedef long long ll;typedef pair<int,int>P;const int INF=0x3f3f3f3f,maxn=100001;int check(int n){    int a[5],res=0;    while(n)    {        a[res++]=n%10,n/=10;    }    for(int i=0;i<res;i++)        for(int j=i+1;j<res;j++)            if(a[i]==a[j])return 0;    return 1;}int main(){       int n;    while(~scanf("%d",&n))    {        for(int i=n+1;;i++)            if(check(i))            {                printf("%d\n",i);                break;            }    }    return 0;}
原创粉丝点击