将给定的单词列表转换为字典的算法原理,是如何使用C语言的程序编写设计的思想方法的代码怎么来做

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

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

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问

相似问题

1
如何用C语言实现求给定矩阵的逆矩阵?
1
编写C程序,对于给定两个目录A,B,使用I/O函数完成两目录下的所有文件的同步。
1
向量和欧几里得的距离的计算,求最短的距离,给定的点,采用C语言算法怎么实现
0
GM的矩阵的算法,GM的大小由输入给定,具体怎么实现,用C语言
0
给定一个长度为偶数位的0,1字符串,运用C编程语言的编程实现串的奇偶位互换。
0
判断给定的解是不是问题的最优解的一个算法, C语言如何才能实现它的
0
给定的整数求最大质因数(LPF)的算法问题,如何运用C编程语言的思路求解
0
在给定的AB之间寻找符合条件的最大值,运用C语言算法技术地实现
0
给定的数字列表构成哪些表达式的问题,如何利用C语言的形式的办法解决
0
给定的汇率然后计算转换的问题,如何运用C语言的形式去解决呢
1
编写一个程序,判断给定的两个数是否是亲和数,使用C语言的程序的设计的方式
0
对于给定的N对双胞胎,是否有一个年龄序列,满足这一规律,如何使用C语言的程序的设计完成这个问题?
0
给定的一个字符串,统计其中数字字符出现的次数,怎么采用C语言来回答这个问题的
0
给定二维的平面上n个不同的点,要求在这些点里寻找三个点的C语言程序设计的做法是什么
0
N对数的排列的规律的算法问题,要求使用C语言的程序的代码编写技术的方式如何实现的呢?
0
输出所有在给定范围内的水仙花数,怎么采用C语言的程序编写代码的技术方式去实现这个程序编写的?
0
读取文本文件并且统计给定文本文件中汉字的个数,怎么利用C语言的程序编程的方式来实现的?
2
怎样将英文句子中出现给定单词的前后加上一个空格后输出?
1
判断给定的范围内不存在水仙花数,如果有输出水仙花数否则输出no,怎么用 C语言的程序设计的
1
一个循环而不是三个循环去统计给定的n个数中,负数、零和正数的个数,怎么用C语言的程序代码的编写技术