All problems

Problem 216

Count Words

Easy · 10 pts · String

Problem

You are given a line of text made of lowercase words and spaces. Count the words. Words are separated by one or more spaces, and the line may also start or end with spaces, so simply counting the spaces does not work. A word starts at every letter whose previous character is a space (or which is the first character of the line). Count those positions, or split the line on runs of spaces and ignore empty pieces.

Input

A single line of lowercase letters and spaces containing at least one word.

Output

Print the number of words.

Constraints

1 <= length of the line <= 100000

Example input

hello   world foo

Example output

3

Explanation

"hello world foo" has three spaces between hello and world, but they separate only two words. The words are hello, world and foo, so the answer is 3.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Shortest Subarray with Sum at Least K Next: Capitalize Each Word