KerimJavati
TCO19 SRM 753 · 2019-03-06 · by minimario
Problem Statement
Kerim Javati is one of the most careless coders in his university. He never knows what to type, and he relies on his friends to tell him when he's wrong. Here is how he types a letter of a command into the computer:
- He types the letter 'a' and looks at his friend. If that is the right letter, the friend nods and Kerim moves on to typing the next letter.
- If the friend shook his head, meaning that 'a' was not the correct letter, Kerim presses backspace to erase the 'a' and he types 'b' instead. Then, he looks at his friend again.
- If 'b' wasn't correct either, he will press backspace to erase it and type 'c'. And so on, through the whole alphabet.
You are given the
Constraints
- Length of text will be between 1 and 50, inclusive.
- text will consist of lowercase English letters only ('a'-'z').
"aaa" Returns: 3
Kerim will simply press the letter 'a' three times and he will be done.
"d" Returns: 7
Kerim will make the following sequence of keystrokes: 'a', backspace, 'b', backspace, 'c', backspace, 'd'. The total number of keystrokes is 7.
"bad" Returns: 11
"topcoder" Returns: 184
"qwertyuiopasdfghjklzxcvbnm" Returns: 676
Submissions are judged against all 61 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class KerimJavati with a public method int howLong(string text) · 61 test cases · 2 s / 256 MB per case