QWERTY Hand Switch Count
InterviewTime limit8sMemory limit512 MB
For each lowercase string until a terminating '#', count how many times the typing hand switches between consecutive characters on the standard QWERTY layout.
- Level
Easy3 of 10
- Topics
- Implementation, String, Simulation
- Solved
- No attempts yet
Problem
Anyone who loves ACM-ICPC wants it so badly their throat is coming out of their hands: Accepted. AC for short. In reality, though, only a very small group of people understands it that way; to the general public it is nothing more than the abbreviation of "koukyoukoukokukikou".
The keyboard layout found on ordinary keyboards (Figure A-1) is called the QWERTY layout, and a different layout called the Dvorak layout has also been devised. In the Dvorak layout the frequently used keys sit at the home position, so Mr. T (pseudonym) insists forcefully that it lets you type faster.

Figure A-1 QWERTY layout
Looking at this string, Mr. T (pseudonym) noticed something. With the Dvorak layout, "koukyoukoukokukikou" can be typed with one hand alone. At the same time, he noticed a disappointing fact: it can also be typed with one hand alone on the QWERTY layout.
Mr. T (pseudonym) became curious whether there were other strings that can be typed with one hand alone on the Dvorak layout. If possible, though, he does not want them to be typeable with one hand alone on the QWERTY layout. So for each string, he decided to write a program that finds the number of times the hand used to type characters switches when typing on the QWERTY layout. Come to think of it, Mr. T (pseudonym) had almost forgotten the QWERTY layout. Let us write the program for him instead.
If you become unsure which hand types each key in the QWERTY layout, refer to Figure A-2 below.

Figure A-2 Ranges typed by each hand
Input
The input contains one string per line, each a string whose number of hand switches must be counted. Each string consists only of lowercase letters and is at most 32 characters long. The end of the input is indicated by a line consisting of only "#". This "#" is not a string to be counted.
Output
For each input string, output one integer per line. The integer to output is the number of times the hand used to type characters switches when the QWERTY layout is used. Do not include any extra characters in the output.