CF180D.Name
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Everything got unclear to us in a far away constellation Tau Ceti. Specifically, the Taucetians choose names to their children in a very peculiar manner.
Two young parents abac and bbad think what name to give to their first-born child. They decided that the name will be the permutation of letters of string s. To keep up with the neighbours, they decided to call the baby so that the name was lexicographically strictly larger than the neighbour's son's name t.
On the other hand, they suspect that a name tax will be introduced shortly. According to it, the Taucetians with lexicographically larger names will pay larger taxes. That's the reason abac and bbad want to call the newborn so that the name was lexicographically strictly larger than name t and lexicographically minimum at that.
The lexicographical order of strings is the order we are all used to, the "dictionary" order. Such comparison is used in all modern programming languages to compare strings. Formally, a string p of length n is lexicographically less than string q of length m, if one of the two statements is correct:
- n < m, and p is the beginning (prefix) of string q (for example, "aba" is less than string "abaa"),
- _p_1 = _q_1, _p_2 = _q_2, ..., p__k - 1 = q__k - 1, p__k < q__k for some k (1 ≤ k ≤ min(n, m)), here characters in strings are numbered starting from 1.
Write a program that, given string s and the heighbours' child's name t determines the string that is the result of permutation of letters in s. The string should be lexicographically strictly more than t and also, lexicographically minimum.
我们在遥远的恒星系——天仓五(Tau Ceti)中,一切都变得模糊不清。具体而言,天仓五人给子女起名的方式极为特别。
两位年轻的父母 abac 和 bbad 正在为其第一个孩子考虑名字。他们决定:孩子的名字必须是字符串 s 的某个字母排列(即重排)。
为了跟上邻居的步伐,他们希望给孩子起一个字典序严格大于邻居儿子的名字 t 的名字。
另一方面,他们怀疑不久后将引入一种“姓名税”:根据该税制,字典序越大的名字,所需缴纳的税额也越高。正因如此,abac 和 bbad 希望为新生儿选取一个满足如下条件的名字:它字典序严格大于名字 t,且在所有满足该条件的 s 的排列中,字典序最小。
字符串的字典序即我们所熟知的“词典”顺序,现代所有编程语言中字符串比较均采用此规则。形式化地,设长度为 n 的字符串 p 与长度为 m 的字符串 q 比较,则 p 字典序小于 q 当且仅当以下两个条件之一成立:
- n<m,且 p 是 q 的前缀(例如,"aba" 小于 "abaa");
- 存在某个 k(1≤k≤min(n,m)),使得 p1=q1,p2=q2,…,pk−1=qk−1,但 pk<qk(此处字符串下标从 1 开始编号)。
请编写一个程序:给定字符串 s 和邻居儿子的名字 t,找出 s 的一个字母排列,使其字典序严格大于 t,且在所有满足该条件的排列中字典序最小。
输入格式
The first line contains a non-empty string s (1 ≤ |s| ≤ 5000), where |s| is its length. The second line contains a non-empty string t (1 ≤ |t| ≤ 5000), where |t| is its length. Both strings consist of lowercase Latin letters.
第一行包含一个非空字符串 s(1 ≤ ∣s∣ ≤ 5000),其中 ∣s∣ 表示其长度。第二行包含一个非空字符串 t(1 ≤ ∣t∣ ≤ 5000),其中 ∣t∣ 表示其长度。两个字符串均由小写拉丁字母组成。
输出格式
Print the sought name or -1 if it doesn't exist.
输出所查找的姓名,如果不存在则输出 -1。
输入输出样例
输入#1
aad aac
输出#1
aad
输入#2
abad bob
输出#2
daab
输入#3
abc defg
输出#3
-1
输入#4
czaaab abcdef
输出#4
abczaa
说明/提示
In the first sample the given string s is the sought one, consequently, we do not need to change the letter order there.
在第一个样例中,给定的字符串 s 即为所求字符串,因此我们无需改变其中字母的顺序。
输入解题思路,AI测评打分。不知道怎么写?