NumberChanger
SRM 221 · 2004-12-01 · by AdminBrett
SRM 221 · 2004-12-01 · by AdminBrett · Brute Force
Problem Statement
Problem Statement
You will be given 2 numbers start and finish each with the same number of digits. Both may have leading zeros. You are going to transform start into finish using the following kinds of transformation steps:
- 1) Increment a digit less than 9 by 1. For example, changing 354 to 364.
- 2) Decrement a digit greater than 0 by 1. For example, changing 354 to 254.
- 3) Swapping two digits. For example, changing 354 to 453.
Constraints
- start will contain between 1 and 8 characters inclusive.
- Each character in start will be a digit ('0'-'9').
- finish will contain the same number of characters as start.
Examples
0)
"01234567" "01234567" Returns: 0
No steps required.
1)
"11119999" "99991111" Returns: 4
4 swaps does the trick.
2)
"55555555" "12345678" Returns: 16
Swapping is of no use here.
3)
"77771111" "00446688" Returns: 16
4)
"00000000" "99999999" Returns: 72
Submissions are judged against all 99 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class NumberChanger with a public method int transform(string start, string finish) · 99 test cases · 2 s / 256 MB per case