#C13966. Length of the Shortest Word
Length of the Shortest Word
Length of the Shortest Word
Given a string s
containing a sentence, your task is to compute the length of the shortest word in the string. A word is defined as a contiguous sequence of non-space characters. If the string does not contain any word (i.e. it is empty or consists only of spaces), output inf
to represent infinity. Note that you are not allowed to use built-in functions that directly compute the minimum (e.g., min()
in Python).
For example:
- Input: "The quick brown fox jumps over the lazy dog" → Output: 3
- Input: "word" → Output: 4
- Input: "cat bat rat" → Output: 3
- Input: "" → Output: inf
Your implementation should read the input from stdin and print the result to stdout.
inputFormat
The input consists of a single line containing the string s
. This string may include spaces. If the input is empty, consider it as having no words.
outputFormat
Output a single value: the length of the shortest word in the input string. If there is no word, print inf
.
The quick brown fox jumps over the lazy dog
3