#CCBCHBON0000037. Nén dãy dấu cách (Collapse Runs of Spaces)
Nén dãy dấu cách (Collapse Runs of Spaces)
Collapse Runs of Spaces
Source: Kernighan & Ritchie
Version: Phuoc Hung OJ Extended
Problem Statement
Read the entire UTF-8 stream to EOF; replace each contiguous run of ordinary spaces (U+0020) by exactly one space. Preserve leading/trailing spaces, tabs, line breaks and all other content. Empty input gives empty output. This PHOJ edition excludes CR and caps length at 100000 bytes.
Input
A UTF-8 stream of at most 100000 bytes, no CR, possibly empty or unterminated.
Output
Output transformed text exactly, without inserting a final newline.
Subtasks
-
Subtask 1 (20%): UTF-8 stream length at most 100 bytes, no CR.
-
Subtask 2 (30%): UTF-8 stream length at most 2000 bytes, no CR.
-
Subtask 3 (50%): UTF-8 stream length at most 100000 bytes, no CR.
Examples
Example 1
Input:
A B C
Output:
A B C
Explanation:
Collapse adjacent ordinary spaces only; tab and newline delimit separate runs. Actual escaped input: "A B\t C\n"; escaped output: "A B\t C\n".
Example 2
Input:
A B
Output:
A B
Explanation:
Collapse adjacent ordinary spaces only; tab and newline delimit separate runs. Actual escaped input: " A B "; escaped output: " A B ".
Example 3
Input:
Output:
Explanation:
Collapse adjacent ordinary spaces only; tab and newline delimit separate runs. Actual escaped input: ""; escaped output: "".
Example 4
Input:
A B
Output:
A B
Explanation:
Collapse adjacent ordinary spaces only; tab and newline delimit separate runs. Actual escaped input: "A\t B"; escaped output: "A\t B".
The quoted forms below use \t for a literal tab, \n for an LF, and \ for a literal backslash; they describe the actual byte stream, not additional characters in input.