首页 > 其他 > 详细

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

时间:2019-10-03 14:50:51      阅读:84      评论:0      收藏:0      [点我收藏+]

链接:

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;
}

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

原文:https://www.cnblogs.com/YDDDD/p/11619549.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!