A8826 | Anagram
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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 $10^{5}$ characters) and consist of uppercase English letters.
输出格式
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.
输入输出样例
输入 #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".
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted