#K37502. Clean String Utility
Clean String Utility
Clean String Utility
You are given a string that may contain unnecessary spaces: leading spaces, trailing spaces, or multiple spaces between words. Your task is to clean the string by removing any leading and trailing whitespace characters, and replacing every sequence of multiple spaces within the string with a single space.
In other words, if the input string is , then you should perform the following operations:
- Remove all whitespace from the beginning and end of (i.e., ).
- Replace each maximal substring of consecutive whitespace characters inside with a single space.
For example, if the input is " Hello, world! ", the output should be "Hello, world!".
The input will be read from standard input (stdin) and the resulting cleaned string should be printed to standard output (stdout).
inputFormat
The input consists of a single line containing a string . The string may include spaces at the beginning, at the end, and in between words.
outputFormat
Output the cleaned string. The output should not have any leading or trailing spaces and should have only one space between words.## sample
Hello, world!
Hello, world!