zoukankan      html  css  js  c++  java
  • A. Distinct Digits ( Codeforces Round #589 (Div. 2) )

    You have two integers ll and rr. Find an integer xx which satisfies the conditions below:

    • lxrl≤x≤r.
    • All digits of xx are different.

    If there are multiple answers, print any of them.

    Input

    The first line contains two integers ll and rr (1lr1051≤l≤r≤105).

    Output

    If an answer exists, print any of them. Otherwise, print 1−1.

    Examples
    input
    Copy
    121 130
    
    output
    Copy
    123
    
    input
    Copy
    98766 100000
    
    output
    Copy
    -1
    
    Note

    In the first example, 123123 is one of the possible answers. However, 121121 can't be the answer, because there are multiple 11s on different digits.

    In the second example, there is no valid answer.

    bool judge(lli num)
    {
        int a[10]={0};
        while(num)
        {
            if( a[ num%10 ]  )
                return 0;
            else 
                a[ num%10 ] = 1;
            num /= 10;
        }
        return 1;
    }
    int main()
    {
        lli l,r;
        cin>>l>>r;
        for(lli i=l;i<=r;i++)
        {
            if(judge(i)){
                cout<<i<<endl;return 0;
            }
     
        }
        cout<<"-1"<<endl;
     
     
        return 0;
    }
    所遇皆星河
  • 相关阅读:
    docker进入mysql命令窗口
    dyoYQoyfRb
    2018icpc 徐州h题
    求逆元
    取模的n种情况
    Eratos筛法(筛选素数)
    扩展欧几里得
    函数库里有三角函数 和反三角函数
    HDU2795线段树入门 简单查询和修改
    快速排序 分析
  • 原文地址:https://www.cnblogs.com/Shallow-dream/p/11650619.html
Copyright © 2011-2022 走看看