Problem 53
Length of Last Word
Easy · 10 pts · String
Problem
You are given a sentence of words separated by spaces. Print the length of its last word, that is, the number of letters in the final word of the line. The simplest way is to split the line into words and take the last one. You can also scan from the end of the line: skip any spaces, then count letters until you reach a space or the start of the line.
Input
A single line containing one or more words of letters separated by spaces.
Output
Print the length of the last word.
Constraints
1 <= length of the line <= 10000
Example input
Hello World
Example output
5
Explanation
In "Hello World", the last word is World. It has 5 letters, so the answer is 5.