首页 > 其他 > 详细

A. Distinct Digits ( Codeforces Round #589 (Div. 2) )

时间:2019-10-10 22:28:35      阅读:389      评论:0      收藏:0      [点我收藏+]

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;
}

 

A. Distinct Digits ( Codeforces Round #589 (Div. 2) )

原文:https://www.cnblogs.com/Shallow-dream/p/11650619.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!