链接:
https://codeforces.com/contest/1228/problem/A
题意:
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.
思路:
水题.
代码:
#include <bits/stdc++.h>
using namespace std;
bool Check(int x)
{
int vis[10] = {0};
while (x)
{
if (vis[x%10] == 1)
return false;
vis[x%10] = 1;
x /= 10;
}
return true;
}
int main()
{
int l, r;
cin >> l >> r;
for (int i = l;i <= r;i++)
{
if (Check(i))
{
cout << i << endl;
return 0;
}
}
puts("-1");
return 0;
}
原文地址:https://www.cnblogs.com/YDDDD/p/11619549.html
时间: 2024-11-06 07:32:00