本文主要是介绍cf1228AA. Distinct Digits,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
A. Distinct Digits
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
You have two integers ? and ?. Find an integer ? which satisfies the conditions below:
?≤?≤?.
All digits of ? are different.
If there are multiple answers, print any of them.
Input
The first line contains two integers ? and ? (1≤?≤?≤105).
Output
If an answer exists, print any of them. Otherwise, print −1.
Examples
inputCopy
121 130
outputCopy
123
inputCopy
98766 100000
outputCopy
-1
Note
In the first example, 123 is one of the possible answers. However, 121 can’t be the answer, because there are multiple 1s on different digits.
In the second example, there is no valid answer.
签到
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>using namespace std;int vis[10];
bool check(int x)
{memset(vis,0,sizeof(vis));while(x){if(vis[x % 10] == 1)return false;vis[x % 10] = 1;x /= 10;}return true;
}int main()
{int l,r;scanf("%d%d",&l,&r);for(int i = l;i <= r;i++){if(check(i)){printf("%d\n",i);return 0;}}printf("-1\n");return 0;
}
这篇关于cf1228AA. Distinct Digits的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!