Codeforces Round #589 (Div. 2) A. Distinct Digits

链接:

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;
}
上一篇:挖矿原理介绍-如何免费获得比特币、ETH 丨区块链知识


下一篇:炽橙科技:用XR技术革新工业领域,开启应用新“视”界