CF254C.Anagram

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

String xx is an anagram of string yy , if we can rearrange the letters in string xx and get exact string yy . 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 ss and tt of the same length, consisting of uppercase English letters. You need to get the anagram of string tt from string ss . You are permitted to perform the replacing operation: every operation is replacing some character from the string ss by any other character. Get the anagram of string tt in the least number of replacing operations. If you can get multiple anagrams of string tt 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 pp of length nn is lexicographically smaller than string qq of the same length, if p1=q1p_{1}=q_{1} , p2=q2p_{2}=q_{2} , ..., pk1=qk1p_{k-1}=q_{k-1} , p_{k}<q_{k} for some kk ( 1<=k<=n1<=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 ss , the second line contains string tt . The strings have the same length (from 11 to 10510^{5} characters) and consist of uppercase English letters.

输出格式

In the first line print zz — the minimum number of replacement operations, needed to get an anagram of string tt from string ss . In the second line print the lexicographically minimum anagram that could be obtained in zz operations.

输入输出样例

  • 输入#1

    ABA
    CBA
    

    输出#1

    1
    ABC
    
  • 输入#2

    CDBABC
    ADCABD
    

    输出#2

    2
    ADBADC
    

说明/提示

The second sample has eight anagrams of string tt , that can be obtained from string ss 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".

首页