-->
当前位置:首页 > 题库

PROGRAMMING:Digital replacement (Ningbo primary school, 2012)

Luz5年前 (2021-05-10)题库470
Weiwei likes to play a number replacement game very much. The number replacement game is like this: give an n-digit positive integer a, and then give you a number sequence B of length M. Weiwei can use some numbers in B to exchange one-to-one with the numbers in each position in a (or choose not to exchange). Of course, the number in each position in B can only be used once at most. The goal of this game is to maximize the value of a after a series of substitutions.
Weiwei is very smart. In the case of few digits, she can always quickly find the maximum value of the last a, but when n is large, Weiwei can't do anything, so she hopes that you can write a program to help her quickly find the maximum value of A.
###Input format:
The input contains three lines. The first line contains two positive integers n, m separated by spaces. The second line is a positive
The integer a (the highest bit of a must not be 0). The third line is a number sequence B of length M.
###Output format:
The output contains only one value in a row, which indicates the maximum possible value of a (the output cannot contain the previous value)
0).
###Input sample 1:
```in
4 3
one thousand and twenty-four
010
```
###Output sample 1:
```out
one thousand one hundred and twenty-four
```
[explanation of input and output example 1]
A 1 in B is swapped with a 0 in the second bit in a.
###Input sample 2:
```in
3 6
eight hundred and seventy-six
one hundred and twenty-three thousand four hundred and fifty-nine
```
###Output sample 2:
```out
nine hundred and seventy-six
```
[data range]
For 20% of the data 1 ≤ n, m ≤ 10 for 50% data 1 ≤ n, m ≤ 2000 for 100% data 1 ≤ n, m ≤ 100000







answer:If there is no answer, please comment