#PCBTAM0000022. Căn giữa văn bản theo độ rộng (Center Align Text)
Căn giữa văn bản theo độ rộng (Center Align Text)
Center Align Text
Version: Phuoc Hung OJ Extended
Problem Statement
Given string and a minimum field width , center by inserting spaces on both sides if . The total number of added spaces is . Split them evenly when possible; if the number is odd, the right side receives the extra space.
If , preserve unchanged. Put a | character at each end to make padding visible.
Input
The first line contains , which may be empty. The second line contains integer .
Output
Print one line in the format |centered_field|. Do not truncate or modify .
Subtasks
- Subtask 1 (100 points): Unicode characters; .
Examples
Example 1
Input
AB
6
Output
| AB |
Explanation. AB has length , leaving four positions in width ; add two spaces on each side.
Example 2
Input
A
4
Output
| A |
Explanation. A has length , leaving three positions; add one space left and two right.
Example 3
Input
Xin
2
Output
|Xin|
Explanation. Xin has length , exceeding width , so it stays unchanged.