303465: CF670F. Restore a Number

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Restore a Number

题意翻译

Vasya要给Kate传一个很大的整数n,他的传输方法是,先把n用字符串的形式表示出来,再在这个字符串后面接上一个数k,k代表字符串n的长度。 但是Kate收到的数是乱序的,她询问Vasya时,Vasya只记得这个字符串n的一个非空子串了。 现在你需要去把n还原成那个很大的整数。由于n有很多种还原方法,你需要输出的是符合题目条件的最小的n。这里的n不含有前导0,除非n=0. 输入:两个字符串,分别代表Kate收到的字符串和n的一个子串,子串可以含有前导0. 输出:一个整数,表示Vasya想传送的整数n的最小值。 样例解释:在第一组样例里,答案长度为5,且包含子串021,所以能产生的结果是30021;在第二组样例中,答案长度为10,且包含子串63,能产生的结果为3036366999。

题目描述

Vasya decided to pass a very large integer $ n $ to Kate. First, he wrote that number as a string, then he appended to the right integer $ k $ — the number of digits in $ n $ . Magically, all the numbers were shuffled in arbitrary order while this note was passed to Kate. The only thing that Vasya remembers, is a non-empty substring of $ n $ (a substring of $ n $ is a sequence of consecutive digits of the number $ n $ ). Vasya knows that there may be more than one way to restore the number $ n $ . Your task is to find the smallest possible initial integer $ n $ . Note that decimal representation of number $ n $ contained no leading zeroes, except the case the integer $ n $ was equal to zero itself (in this case a single digit 0 was used).

输入输出格式

输入格式


The first line of the input contains the string received by Kate. The number of digits in this string does not exceed $ 1000000 $ . The second line contains the substring of $ n $ which Vasya remembers. This string can contain leading zeroes. It is guaranteed that the input data is correct, and the answer always exists.

输出格式


Print the smalles integer $ n $ which Vasya could pass to Kate.

输入输出样例

输入样例 #1

003512
021

输出样例 #1

30021

输入样例 #2

199966633300
63

输出样例 #2

3036366999

Input

题意翻译

Vasya要给Kate传一个很大的整数n,他的传输方法是,先把n用字符串的形式表示出来,再在这个字符串后面接上一个数k,k代表字符串n的长度。 但是Kate收到的数是乱序的,她询问Vasya时,Vasya只记得这个字符串n的一个非空子串了。 现在你需要去把n还原成那个很大的整数。由于n有很多种还原方法,你需要输出的是符合题目条件的最小的n。这里的n不含有前导0,除非n=0. 输入:两个字符串,分别代表Kate收到的字符串和n的一个子串,子串可以含有前导0. 输出:一个整数,表示Vasya想传送的整数n的最小值。 样例解释:在第一组样例里,答案长度为5,且包含子串021,所以能产生的结果是30021;在第二组样例中,答案长度为10,且包含子串63,能产生的结果为3036366999。

加入题单

算法标签: