LittleElephantAndString
SRM 597 · 2013-06-25 · by Witaliy
Problem Statement
Little Elephant from the Zoo of Lviv likes strings.
You are given a
Constraints
- A will contain between 1 and 50 characters, inclusive.
- B will contain between 1 and 50 characters, inclusive.
- A and B will be of the same length.
- A and B will consist of uppercase letters ('A'-'Z') only.
"ABC" "CBA" Returns: 2
The optimal solution is to make two turns. On the first turn, choose character 'B' and obtain string "BAC". On the second turn, choose character 'C' and obtain "CBA".
"A" "B" Returns: -1
In this case, it's impossible to transform A into B.
"AAABBB" "BBBAAA" Returns: 3
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" "ZYXWVUTSRQPONMLKJIHGFEDCBA" Returns: 25
"A" "A" Returns: 0
Submissions are judged against all 199 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class LittleElephantAndString with a public method int getNumber(string A, string B) · 199 test cases · 2 s / 256 MB per case