#CCBCHBON0000038. Hiển thị ký tự điều khiển (Display Escape Sequences)
Hiển thị ký tự điều khiển (Display Escape Sequences)
Display Escape Sequences
Source: Kernighan & Ritchie
Version: Phuoc Hung OJ Extended
Problem Statement
Read text to EOF. Replace each actual tab by the two printable characters backslash+t, each actual newline by backslash+n, and each actual backslash by two backslashes. Preserve other characters and do not reprocess produced output. The original K&R 1-10 uses backspace; the newline rule is specific to this PHOJ adaptation.
Input
UTF-8 text up to 100000 bytes, excluding CR, possibly empty or not newline-terminated.
Output
Print the visible escaped stream without adding a 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\D
Output:
A\tB\nC\\D
Explanation:
Actual tab, newline and backslash are escaped once; produced characters are not processed again. Actual escaped input: "A\tB\nC\\D"; escaped output: "A\\tB\\nC\\\\D".
Example 2
Input:
\t
Output:
\\t
Explanation:
Actual tab, newline and backslash are escaped once; produced characters are not processed again. Actual escaped input: "\\t"; escaped output: "\\\\t".
Example 3
Input:
Output:
Explanation:
Actual tab, newline and backslash are escaped once; produced characters are not processed again. Actual escaped input: ""; escaped output: "".
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.