当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

1750:Dictionary

题目描述
Authors of the new, all-in-one encyclopedia have organized the titles in the order they consider most appropriate for their readers. It's not always alphabetical, because they want to observe some peculiar relationships between them. However, they still want to allow users to look up titles quickly.

They achieve this by adding a carefully calculated number of spaces before every title in the list of titles. They call this structure a dictionary.

A dictionary is represented by a list of words with some number of spaces before certain words. Dictionary format can be described as a set of constraints on sequences of consecutive words starting with the same letter. Any maximal sequence of consecutive words starting with the same letter should satisfy the following rules:

  • The first word in the group has no spaces before it. Every subsequent word in the group has at least one leading space.
  • If
    • the first word of the group is deleted and
    • one space is deleted before every remaining word and
    • the first letter is deleted from every remaining word

    then resulting sequence is a dictionary.

The authors don't feel like giving you a more detailed explanation of what a dictionary is, so they have included an example (see sample input and output) that clarifies their definition.
Your task is to write a program that will convert a given list of words into a dictionary by adding some number of spaces before certain words and preserving the original order of the words.
输入解释
The input consists of at least one and most 100000 words. Each word consists of at least one and at most 10 lower-case letters. There will be no leading or trailing spaces. There will be no blank lines between the words, but there may be an arbitrary number of blank lines at the end of the file.
输出解释
Write to the output the original words in the same order without any trailing spaces but with the appropriate number of leading spaces, so that this word list is a dictionary. There should be no blank lines between the words, but there may be an arbitrary number of blank lines at the end of the file.
输入样例
a
ant
antique
amaze
bargain
bridge
bride
bribe
born
bucket
tart
tan
tram
trolley
t
try
trial
zed
double
dorm
do
dormant
donate
again
agony
boost
back
born
输出样例
a
 ant
  antique
 amaze
bargain
 bridge
  bride
   bribe
 born
 bucket
tart
 tan
 tram
  trolley
 t
 try
  trial
zed
double
 dorm
  do
  dormant
  donate
again
 agony
boost
 back
 born

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-1750

最后修改于 2020-10-29T06:13:04+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 10000