21128_Dictionary

2022-5-16 18:18| 发布者: Hocassian| 查看: 50| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-3-89504877085699-Problem List-采集的数据-后羿采集器.html

Pro.ID

21128

Title

Dictionary

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21128

AC

34

Submit

132

Ratio

25.76%

时间&空间限制

  • Time Limit: 1000/500 MS (Java/Others)     Memory Limit: 65536/32768 K (Java/Others)
  • 描述

    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.

    输出

    Description

    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.

    Input

    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.

    Output

    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.

    Sample Input

    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

    Sample Output

    NOTE: For reading convenience spaces are replaced with '.' characters. Your output file should contain spaces instead.

    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

    Source

    样例输入

    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

    样例输出

    NOTE: For reading convenience spaces are replaced with '.' characters. Your output file should contain spaces instead.

    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

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部