Practice

Tokenise a Sentence into Words

2023/May/June·Variant 1
MEDIUMString Processing

A sentence contains words separated by single spaces, with no leading or trailing spaces. Write procedure SplitWords(Sentence) that outputs each word on its own line.

Input: One sentence. Output: Each word on its own line.

Example:

Input:  The cat sat
Output: The
        cat
        sat

Sample Test Cases

Test 1: Three words
Inputs: The cat sat
Expected: The cat sat
Test 2: Single word, no spaces
Inputs: Hello
Expected: Hello

Premium Question

This question needs a paid plan — upgrade, or join a class from a teacher who has one. You can read the description and sample tests, but grading is locked.

Sign in to get started