#C13055. Word Lengths in a Sentence
Word Lengths in a Sentence
Word Lengths in a Sentence
You are given a sentence that may contain punctuation. Your task is to determine the lengths of the shortest and longest words in the sentence.
A word is defined as a maximal substring of alphanumeric characters (including underscores), i.e. it matches the regular expression \b\w+\b
in LaTeX: \(\texttt{\textbackslash b\textbackslash w+\textbackslash b}\). If the sentence does not contain any word, return 0 for both the shortest and longest word lengths.
Examples:
- Input: "The quick brown fox jumps over the lazy dog" → Output: 3 5
- Input: "To be, or not to be, that is the question!" → Output: 2 8
- Input: "" or "!!!..." → Output: 0 0
You need to read all input from standard input and print the result to standard output.
inputFormat
The first line of input contains a single integer T
(1 ≤ T ≤ 100), representing the number of test cases. Each of the following T
lines contains a sentence. The sentence may include letters, digits, punctuation, and spaces.
Example input:
3 The quick brown fox jumps over the lazy dog To be, or not to be, that is the question! !!!...
outputFormat
For each test case, print a single line containing two integers separated by a space: the length of the shortest word and the length of the longest word in the corresponding sentence.
Example output:
3 5 2 8 0 0## sample
1
The quick brown fox jumps over the lazy dog
3 5
</p>