You have two integers ll and rr. Find an integer xx which satisfies the conditions below:
If there are multiple answers, print any of them.
The first line contains two integers ll and rr (1≤l≤r≤1051≤l≤r≤105).
If an answer exists, print any of them. Otherwise, print −1−1.
121 130
123
98766 100000
-1
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