Excessive Space Remover

How do you remove consecutive spaces in a simple editor like notepad in Microsoft Windows? One way is to repeatedly “replace all” two consecutive spaces with one space (we call it an action). In this problem, you’re to simulate this process and report the number of such “replace all” actions. For example, if you want to remove consecutive spaces in “A very big joke.”, you need two actions: Averybigjoke.'' -> Averybigjoke.'' -> ``Averybigjoke.'' Input The input contains multiple test cases, one in a separate line. Each line contains letters, digits, punc- tuations and spaces (possibly leading spaces, but no trailing spaces). There will be no TAB character in the input. The size of input does not exceed 1MB. Output For each line, print the number of actions that are required to remove all the consecutive spaces. Explanation If you can’t see clearly, here is the sample input, after replacing spaces with underscores: A*very␣␣big␣␣␣␣joke. ␣␣␣␣␣␣␣␣␣Goodbye! Sample Input A very big joke. Goodbye! Sample Output 2 4