CF748B.Santa Claus and Keyboard Check
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be.
In order to make sure that he's right and restore the correct order of keys, Santa typed his favorite patter looking only to his keyboard.
You are given the Santa's favorite patter and the string he actually typed. Determine which pairs of keys could be mixed. Each key must occur in pairs at most once.
圣诞老人决定拆开他的键盘进行清洁。当他把所有按键重新装回去后,突然意识到某些按键对互换了位置!也就是说,圣诞老人怀疑每个按键要么在它原本的位置上,要么在另一个按键的位置上,而那个按键恰好位于该按键本应所在的位置。
为了确认自己的猜测并恢复按键的正确顺序,圣诞老人仅看着键盘,输入了他最喜欢的字符串(pattern)。
你将获得圣诞老人最喜欢的字符串(pattern)以及他实际输入的字符串。请确定哪些按键对可能发生了互换。每个按键最多只能出现在一个互换对中。
输入格式
The input consists of only two strings s and t denoting the favorite Santa's patter and the resulting string. s and t are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.
输入仅包含两个字符串 s 和 t,分别表示圣诞老人喜爱的模式串和最终得到的字符串。s 和 t 均非空,且长度相同,长度至多为 1000。两个字符串均由小写英文字母组成。
输出格式
If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes).
Otherwise, the first line of output should contain the only integer k (k ≥ 0) — the number of pairs of keys that should be swapped. The following k lines should contain two space-separated letters each, denoting the keys which should be swapped. All printed letters must be distinct.
If there are several possible answers, print any of them. You are free to choose the order of the pairs and the order of keys in a pair.
Each letter must occur at most once. Santa considers the keyboard to be fixed if he can print his favorite patter without mistakes.
如果圣诞老人错了,即不存在一种方法将某些按键分成若干对,并在每对中交换两个按键,从而使键盘恢复正常,则输出 \-1(不带引号)。
否则,输出的第一行应仅包含一个整数 k(k≥0),表示需要交换的按键对数。接下来的 k 行每行应包含两个用空格分隔的字母,表示需要交换的一对按键。所有输出的字母必须互不相同。
若存在多种可能的答案,输出任意一种即可。你可以自由选择各对按键的顺序,以及每对中两个按键的顺序。
每个字母至多出现一次。圣诞老人认为键盘已修复,当且仅当他能够无错误地输入他最喜爱的字符串。
输入输出样例
输入#1
helloworld ehoolwlroz
输出#1
3 h e l o d z
输入#2
hastalavistababy hastalavistababy
输出#2
0
输入#3
merrychristmas christmasmerry
输出#3
-1
输入解题思路,AI测评打分。不知道怎么写?