Problem Statement
Fox Ciel wants to type a word on her old cell phone. The cell phone has only one button. The letter A is typed by tapping the button once, B by tapping it twice in a row, and so on, in alphabetical order. Thus, the last letter Z is typed by tapping the button 26 times without a pause.
You are given a String word. Compute and return the answer to the following question: How many times will Ciel tap the button while typing this word?
You are given a String word. Compute and return the answer to the following question: How many times will Ciel tap the button while typing this word?
Definition
- Class:
- WritingWords
- Method:
- write
- Parameters:
- String
- Returns:
- int
- Method signature:
- int write(String word)
- (be sure your method is public)
Notes
- While typing a word, Ciel has to make a short pause after typing each letter, so that the phone can tell when one letter ends and another letter begins. These pauses do not matter in this problem.
Constraints
- word will contain between 1 and 50 characters, inclusive.
- Each character in word will be an uppercase English letter ('A'-'Z').
Examples
"A"
Returns: 1
One tap types the letter A."ABC"
Returns: 6
To type ABC, Ciel will do the following: Tap the button once to type A. Tap the button twice to type B. Tap the button three times to type C. The total number of taps is 1+2+3 = 6."VAMOSGIMNASIA"
Returns: 143
"TOPCODER"
Returns: 96
"SINGLEROUNDMATCH"
Returns: 183
"ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"
Returns: 1300