#K37502. Clean String Utility

    ID: 25990 Type: Default 1000ms 256MiB

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 SS, then you should perform the following operations:

  1. Remove all whitespace from the beginning and end of SS (i.e., trim(S)\text{trim}(S)).
  2. Replace each maximal substring of consecutive whitespace characters inside SS 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 SS. 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!