NameInput
Member SRM 461 · 2009-12-03 · by dolphinigle
Problem Statement
- Initially, the handheld shows the first character in the prediction sequence.
- If the user presses the 'up' key, the handheld shows the next character in the sequence (or the first character in the sequence if it was showing the last character).
- If the user presses the 'down' key, it shows the preceeding character in the sequence (or the last character in the sequence if it was showing the first character).
- If the user presses the 'enter' key, then the character currently shown by the handheld is input (the character shown by the handheld remains the same).
You are given
Notes
- Both your name and the prediction sequence are case sensitive, that is, B is different from b and d is different from D.
Constraints
- predictionSequence will contain between 1 and 50 elements, inclusive.
- Each element of predictionSequence will contain between 1 and 50 characters, inclusive.
- Each character in each element of predictionSequence will be a lowercase letter ('a'-'z'), an uppercase letter ('A'-'Z') or a digit ('0'-'9').
- name will contain between 1 and 50 elements, inclusive.
- Each element of name will contain between 1 and 50 characters, inclusive.
- Each character in each element of name will be a lowercase letter ('a'-'z'), an uppercase letter ('A'-'Z') or a digit ('0'-'9').
{"Jjhon"}
{"John"}
Returns: 5
Press enter, down, down, enter, down, enter, up, up, enter. This will complete the name input process and use only 5 up and down keypresses.
{"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ","0123456789"}
{"Joh","nAndFr","iends"}
Returns: 186
To obtain the full prediction sequence concatenate all the elements of predictionSequence. To obtain the full name concatenate all the elements of name. This yields "JohnAndFriends".
{"aaaabbbab","baabbabaabba"}
{"bbaaababba","baababababbb"}
Returns: 16
Multiple occurences of characters may be present in both parameters.
{"john"}
{"John"}
Returns: -1
Since it is case sensitive it is impossible to input the letter 'J'.
{"4"}
{"4444444444444"}
Returns: 0
Press enter 13 times.
Submissions are judged against all 127 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class NameInput with a public method int countUpDownKeyPresses(vector<string> predictionSequence, vector<string> name) · 127 test cases · 2 s / 256 MB per case