CodeForces - 1228A Distinct Digits
题目:
You have two integers l and r. Find an integer x which satisfies the conditions below:
- l≤x≤r.
- All digits of x are different.
If there are multiple answers, print any of them.
Input
The first line contains two integers ll and r (1≤l≤r≤105).
Output
If an answer exists, print any of them. Otherwise, print −1
Sample Input
121 130
Sample Output
123
Sample Input
98766 100000
Sample Output
-1
题目大意:
在 区间 [l,r] 之间 有没有一个数 , 它各个位上的数字都不同 , 如果有就输出这个数 ,没有就输出 -1 .
题目分析:
这个 模拟就好了 ,一个一个 找 ,
#include <stdio.h>
int main(){
int l,r,i,a[10]={0},j;//数组a 表示各个数,0~9
scanf("%d%d",&l,&r);
for(;l<=r;l++)
{ j=l;
for(;j>0;)
{
a[j%10]++;
j=j/10;
}//把数 拆解出来
if(a[0]<2 &&a[1]<2 &&a[2]<2 &&a[3]<2 &&a[4]<2 &&a[5]<2 &&a[6]<2 && a[7]<2 &&a[8]<2 &&a[9]<2)//这里 就是判断 各个位数上的数是否重复。
{
printf("%d",l);//如果没有重复,输出这个数,
return 0;}
else
{
for (i=0;i<10;i++)
a[i]={0};
continue; } //再来一次,继续找。
}
printf("-1");
}