CF81B.Sequence Formatting

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

波利卡普非常细心。他输入数字序列时也格外谨慎,不像他的同学们。如果他看到序列中逗号后面没有空格、出现连续两个空格,或者任何其他看起来不整齐的地方,他都会立刻进行修正。例如,将形如 "1,2 ,3,..., 10" 的数字序列修正为 "1, 2, 3, ..., 10"。

本题中,你将得到一个字符串 ss,它由若干项拼接而成;每一项可能是以下之一:

  • 任意长度的正整数(不允许前导零),
  • 一个逗号符号 ",",
  • 一个空格符号 " ",
  • 三个连续的点 "..."(即严格由三个英文句点 . 组成,也称为省略号)。

波利卡普希望在字符串 ss 中添加或删除空格,使其满足如下条件:

  • 每个逗号后面恰好跟一个空格(若逗号位于字符串末尾,则此规则对该逗号不适用);
  • 每个 "..."(省略号)前面恰好有一个空格(若省略号位于字符串开头,则此规则对该省略号不适用);
  • 若两个相邻的数字之间仅由空格分隔(一个或多个空格),则应仅保留其中一个空格;
  • 字符串中不应存在其他空格。

请自动化完成波利卡普的工作,编写一个程序来处理给定的字符串 ss。

输入格式

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.

输入数据包含一个字符串 ss,其长度为 11 至 255255 个字符。字符串 ss 的首尾均不为空格,且其内容符合上述描述。

输出格式

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.

打印处理后的字符串 ss。您的程序输出应与预期答案完全一致。允许在输出行末添加换行符,也允许不添加换行符。

输入输出样例

  • 输入#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, ...

输入解题思路,AI测评打分。不知道怎么写?

首页