CodeForces - 1228A Distinct Digits (简单 模拟)

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");
	}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值