cf1228AA. Distinct Digits

2024-04-16 02:38
文章标签 distinct digits cf1228aa

本文主要是介绍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的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/907598

相关文章

Java Stream的distinct去重原理分析

《JavaStream的distinct去重原理分析》Javastream中的distinct方法用于去除流中的重复元素,它返回一个包含过滤后唯一元素的新流,该方法会根据元素的hashcode和eq... 目录一、distinct 的基础用法与核心特性二、distinct 的底层实现原理1. 顺序流中的去重

详解MySQL中DISTINCT去重的核心注意事项

《详解MySQL中DISTINCT去重的核心注意事项》为了实现查询不重复的数据,MySQL提供了DISTINCT关键字,它的主要作用就是对数据表中一个或多个字段重复的数据进行过滤,只返回其中的一条数据... 目录DISTINCT 六大注意事项1. 作用范围:所有 SELECT 字段2. NULL 值的特殊处

uva 10061 How many zero's and how many digits ?(不同进制阶乘末尾几个0)+poj 1401

题意是求在base进制下的 n!的结果有几位数,末尾有几个0。 想起刚开始的时候做的一道10进制下的n阶乘末尾有几个零,以及之前有做过的一道n阶乘的位数。 当时都是在10进制下的。 10进制下的做法是: 1. n阶位数:直接 lg(n!)就是得数的位数。 2. n阶末尾0的个数:由于2 * 5 将会在得数中以0的形式存在,所以计算2或者计算5,由于因子中出现5必然出现2,所以直接一

ural 1014. Product of Digits贪心

1014. Product of Digits Time limit: 1.0 second Memory limit: 64 MB Your task is to find the minimal positive integer number  Q so that the product of digits of  Q is exactly equal to  N. Inpu

【FZU】2105 Digits Count 线段树

传送门:【FZU】2105 Digits Count 题目分析:与、或、异或三种操作都是每一位相互独立的,所以可以将线段树建四棵,分别对应一位,and和or操作相当于覆盖操作,xor操作相当于反转操作,就和普通的线段树方法类似,设立两个lazy标记即可。查询的时候求得每一位的1的个数*权重(1,2,4,8),全部累加就是答案。 代码如下: #include <cst

Longest Substring with At Most K Distinct Characters

Given a string, find the length of the longest substring T that contains at mostk distinct characters. For example,Given s = “eceba” and k = 2, T is "ece" which its length is 3. 思路:跟  Longest Sub

Longest Substring with At Most Two Distinct Characters

Given a string, find the length of the longest substring T that contains at most 2 distinct characters. For example,Given s = “eceba”, T is "ece" which its length is 3. 思路:同向双指针,跟Longest Substrin

Subtract the Product and Sum of Digits of an Integer

Given an integer number n, return the difference between the product of its digits and the sum of its digits. Example 1: Input: n = 234Output: 15 Explanation: Product of digits = 2 * 3 * 4 = 24

iReport利用Print Repeated Values做分组报表以及对重复值做distinct运算

iReport自带的分组功能有可能是比较符合西方的分组标准,对于中国人来说希望显示方便、节省纸张,对于iReport实现起来就稍微复杂一点了。 本文所用demo地址:http://download.csdn.net/detail/u013284604/6812623 iReport版本 5.1.0,demo所用数据源:json数据源 一、iReport利用Print Repeated Val

java 2.6** Summing the digits in an integer

例如 : 999 process: sum=9+9+9=27; 例如 : 932 process: sum=9+3+2=14;   import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner input=new Scanner(System.in);int