CF254C.Anagram
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
String x is an anagram of string y, if we can rearrange the letters in string x and get exact string y. For example, strings "DOG" and "GOD" are anagrams, so are strings "BABA" and "AABB", but strings "ABBAC" and "CAABA" are not.
You are given two strings s and t of the same length, consisting of uppercase English letters. You need to get the anagram of string t from string s. You are permitted to perform the replacing operation: every operation is replacing some character from the string s by any other character. Get the anagram of string t in the least number of replacing operations. If you can get multiple anagrams of string t in the least number of operations, get the lexicographically minimal one.
The lexicographic order of strings is the familiar to us "dictionary" order. Formally, the string p of length n is lexicographically smaller than string q of the same length, if _p_1 = _q_1, _p_2 = _q_2, ..., p__k - 1 = q__k - 1, p__k < q__k for some k (1 ≤ k ≤ n). Here characters in the strings are numbered from 1. The characters of the strings are compared in the alphabetic order.
字符串 x 是字符串 y 的一个变位词(anagram),当且仅当我们能够重新排列字符串 x 中的字母,从而恰好得到字符串 y。例如,字符串 "DOG" 和 "GOD" 是变位词,字符串 "BABA" 和 "AABB" 也是变位词;但字符串 "ABBAC" 和 "CAABA" 不是。
给你两个长度相同的字符串 s 和 t,它们均由大写英文字母组成。你需要将字符串 s 变为字符串 t 的一个变位词。你被允许执行字符替换操作:每次操作可将字符串 s 中的某个字符替换为任意其他字符。要求用最少次数的替换操作得到 t 的一个变位词。如果存在多种方案均能以最少操作次数得到 t 的变位词,请选择其中字典序最小的那个结果。
字符串的字典序即我们所熟知的“字典”顺序。形式化地,设长度为 n 的字符串 p 和长度同为 n 的字符串 q,若存在某个 k(1≤k≤n),使得 p1=q1,p2=q2,…,pk−1=qk−1,且 pk<qk,则称 p 在字典序上小于 q。此处字符串下标从 1 开始编号,字符之间的大小关系按字母表顺序确定。
输入格式
The input consists of two lines. The first line contains string s, the second line contains string t. The strings have the same length (from 1 to 105 characters) and consist of uppercase English letters.
输入包含两行。第一行包含字符串 s,第二行包含字符串 t。两个字符串长度相同(长度范围为 1 到 105),且均由大写英文字母组成。
输出格式
In the first line print z — the minimum number of replacement operations, needed to get an anagram of string t from string s. In the second line print the lexicographically minimum anagram that could be obtained in z operations.
第一行输出 z —— 将字符串 s 变为字符串 t 的一个变位词(anagram)所需的最少替换操作次数。
第二行输出在 z 次操作下能得到的字典序最小的变位词。
输入输出样例
输入#1
ABA CBA
输出#1
1 ABC
输入#2
CDBABC ADCABD
输出#2
2 ADBADC
说明/提示
The second sample has eight anagrams of string t, that can be obtained from string s by replacing exactly two letters: "ADBADC", "ADDABC", "CDAABD", "CDBAAD", "CDBADA", "CDDABA", "DDAABC", "DDBAAC". These anagrams are listed in the lexicographical order. The lexicographically minimum anagram is "ADBADC".
第二个样例中有八个字符串 t 的变位词,它们可以通过恰好替换字符串 s 中的两个字母得到:“ADBADC”、“ADDABC”、“CDAABD”、“CDBAAD”、“CDBADA”、“CDDABA”、“DDAABC”、“DDBAAC”。这些变位词按字典序排列。其中字典序最小的变位词是 “ADBADC”。
输入解题思路,AI测评打分。不知道怎么写?