EllysString
SRM 534 · 2011-11-22 · by rng_58
Problem Statement
Elly can perform two types of operations:
- Choose a character and replace it with another character. For example, she can change "topcoder" to "topcodfr" by replacing character 6 (0-based index) with 'f'.
- Choose two adjacent letters and swap them. For example, she can change "topcoder" to "tocpoder" by swapping characters 2 and 3 (0-based indices). She cannot change "topcoder" to "topdocer" because the characters being swapped must be adjacent.
Constraints
- s and t will contain between 1 and 50 elements, inclusive.
- Each element of s and t will contain between 1 and 50 characters, inclusive.
- Each character in s and t will be a lowercase letter ('a'-'z').
- s and t will contain the same number of characters when concatenated.
{"usagi"}
{"unagi"}
Returns: 1
Replace character 1 with 'n'.
{"unagi"}
{"nugai"}
Returns: 2
In the first operation, swap characters 0 and 1 to get "nuagi". In the second operation, swap characters 2 and 3 to get "nugai".
{"ellys", "string"}
{"e", "ll", "ysst", "ring"}
Returns: 0
Don't forget to concatenate strings. Both S and T are "ellysstring", so no operation is required.
{"ackwgkbskceehauirbgkagkshiuafdkv"}
{"bckwgksbkceeahlirgbkamkshiaufkdv"}
Returns: 8
{"abcdefghijklmnopqrstuvwxyz"}
{"bcdefghijklmnopqrstuvwxyza"}
Returns: 25
{"fox"}
{"xfo"}
Returns: 2
In the first operation, swap characters 1 and 2 to get "fxo". In the second operation, swap characters 0 and 1 to get "xfo".
{"salmon"}
{"camlon"}
Returns: 2
In the first operation, replace character 0 with 'c' to get "calmon". In the second operation, swap characters 2 and 3 to get "camlon".
{"abcdxyefghzijklmnopv", "abcdxyefghzijklmnopv", "abcdxyefghzijklmnopv", "abcdxyefghzijklmnopv", "abcdxyefghzijklmnopv"}
{"xabcdefghyijklzvmnop", "xabcdefghyijklzvmnop", "xabcdefghyijklzvmnop", "xabcdefghyijklzvmnop", "xabcdefghyijklzvmnop"}
Returns: 80
This fails my first solution (espr1t)
{"xyab"}
{"axby"}
Returns: 3
This fails my second solution (espr1t).
Submissions are judged against all 177 archived test cases, of which 9 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class EllysString with a public method int theMin(vector<string> s, vector<string> t) · 177 test cases · 2 s / 256 MB per case