MnemonicMemory
SRM 357 · 2007-07-12 · by ValD
Problem Statement
It is often helpful to have a mnemonic phrase handy for a math test. For example, the number 25735 can be remembered as "is there anybody out there". If we count the number of characters in every word, we would get the sequence 2, 5, 7, 3, 5, which represents the original number!
Unfortunately for you, your professor likes to make the students memorize random numbers and then test them. To beat the system, your plan is to come up with mnemonic phrases that will represent the numbers you must memorize.
You are given a
Constraints
- dictionary will contain between 1 and 50 elements, inclusive.
- Each element of dictionary will contain between 1 and 9 characters, inclusive.
- Each element of dictionary will contain only lowercase letters ('a'-'z').
- number will contain between 1 and 50 characters, inclusive.
- number will contain only digits between '1' and '9', inclusive.
- There will always be a possible solution with the given dictionary.
"25735"
{"is", "there", "anybody", "out", "there"}
Returns: "is there anybody out there"
The example from the problem statement.
"31415926"
{"may", "i", "have", "a", "large", "container", "of", "coffee"}
Returns: "may a have i large container of coffee"
Make sure you use words of the same length in alphabetical order.
"1212"
{"a", "aa", "a", "aa"}
Returns: "a aa a aa"
"11111111122"
{"a", "b", "d", "c", "a", "e", "f", "z", "zz", "za", "az", "e"}
Returns: "a a b c d e e f z az za"
"2222"
{"ab", "cd", "ef", "a", "b", "ab"}
Returns: "ab ab cd ef"
Submissions are judged against all 45 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class MnemonicMemory with a public method string getPhrase(string number, vector<string> dictionary) · 45 test cases · 2 s / 256 MB per case