A8101 | Sequence Formatting
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected to "1, 2, 3, ..., 10".
In this task you are given a string $s$ , which is composed by a concatination of terms, each of which may be:
- a positive integer of an arbitrary length (leading zeroes are not allowed),
- a "comma" symbol (","),
- a "space" symbol (" "),
- "three dots" ("...", that is, exactly three points written one after another, also known as suspension points).
Polycarp wants to add and remove spaces in the string $s$ to ensure the following:
- each comma is followed by exactly one space (if the comma is the last character in the string, this rule does not apply to it),
- each "three dots" term is preceded by exactly one space (if the dots are at the beginning of the string, this rule does not apply to the term),
- if two consecutive numbers were separated by spaces only (one or more), then exactly one of them should be left,
- there should not be other spaces.
Automate Polycarp's work and write a program that will process the given string $s$ .
In this task you are given a string $s$ , which is composed by a concatination of terms, each of which may be:
- a positive integer of an arbitrary length (leading zeroes are not allowed),
- a "comma" symbol (","),
- a "space" symbol (" "),
- "three dots" ("...", that is, exactly three points written one after another, also known as suspension points).
Polycarp wants to add and remove spaces in the string $s$ to ensure the following:
- each comma is followed by exactly one space (if the comma is the last character in the string, this rule does not apply to it),
- each "three dots" term is preceded by exactly one space (if the dots are at the beginning of the string, this rule does not apply to the term),
- if two consecutive numbers were separated by spaces only (one or more), then exactly one of them should be left,
- there should not be other spaces.
Automate Polycarp's work and write a program that will process the given string $s$ .
输入格式
The input data contains a single string $s$ . Its length is from 1 to 255 characters. The string $s$ does not begin and end with a space. Its content matches the description given above.
输出格式
Print the string $s$ after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it.
输入输出样例
输入 #1
1,2 ,3,..., 10
输出 #1
1, 2, 3, ..., 10
输入 #2
1,,,4...5......6
输出 #2
1, , , 4 ...5 ... ...6
输入 #3
...,1,2,3,...
输出 #3
..., 1, 2, 3, ...
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted