Problems > Tidy the Spaces

Tidy the Spaces

Difficulty: 900 2000 ms 128 MB

strings

Collapse every run of spaces to a single space and strip leading/trailing spaces.

Input: one line of words separated by arbitrary numbers of spaces (possibly leading/trailing).

Output: the tidied line.

Constraints:

  • 1 ≤ length ≤ 104
  • at least one word

Sample Tests

Input 1
  hello   world 
Output 1
hello world
Input 2
a b
Output 2
a b

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.