luogu#P8044. [COCI 2015/2016 #4] YODA

[COCI 2015/2016 #4] YODA

Background

A long, long time ago, in a galaxy far, far away, a giant integer collision was taking place.

Problem Description

What happens when two integers collide? First, keep adding leading 00 digits to the front of the number with fewer digits until both numbers have the same number of digits. Then, starting from the least significant digit, compare the corresponding digits of the two numbers each time, and delete the smaller digit (if the two digits are equal, do nothing). Repeat this process toward higher digits until the most significant digit.

After that, concatenate (in order) the digits that were not deleted in each number to form two new numbers.

For example, for 456328456328 and 284315284315, the collision process is as follows:

44  5 \sout{~5~} 66 33 22 88
 2 \sout{~2~} 88  4 \sout{~4~} 33  1 \sout{~1~}  5 \sout{~5~}

It is easy to see that after the collision, the two new numbers are 4632846328 and 8383.

Now given two numbers n,mn, m, find the new numbers obtained after they collide. If a number has all its digits deleted after the collision, output the string YODA on its line. See the Output Format section for details.

Input Format

The first line contains an integer nn, the first number to collide.
The second line contains an integer mm, the second number to collide.

Output Format

Output two lines.

On the first line, if all digits of nn have been deleted, output the string YODA; otherwise output an integer, the new number obtained from nn after the collision.
On the second line, if all digits of mm have been deleted, output the string YODA; otherwise output an integer, the new number obtained from mm after the collision.

300
500
0
500
65743
9651
673
95
2341
6785
YODA
6785

Hint

[Sample Explanation 2]

For sample 22, the collision process of the two numbers is as follows:

66  5 \sout{~5~} 77  4 \sout{~4~} 33
 0 \sout{~0~} 99  6 \sout{~6~} 55  1 \sout{~1~}

Therefore, after the collision, the two new numbers are 673673 and 9595.

[Constraints]

For 30%30\% of the testdata, nn and mm are guaranteed to be three-digit numbers.
For all testdata, 1n,m1091 \leqslant n, m \leqslant 10^9.

[Source]

This problem comes from COCI 2015-2016 CONTEST 4 T1 YODA. Using the original testdata configuration, the full score is 5050 points.

Translated and organized by Eason_AC.

Translated by ChatGPT 5