英文单词的编码的算法问题,如何利用C语言程序编写来解决?

Problem Description
In any language, certain combinations of letters do not appear (or at least appear so seldom that they can be considered non-existent). For instance, there are no English words containing the three letter combination buv as a substring. Given a list of letter combinations that do not exist, the number of possible “words” in a language can be reduced a lot (a “word” here means any combination of letters that doesn’t contain any of the given letter combinations as a substring). If we order all such words by increasing length, ordering words of the same length alphabetically, we can enumerate them starting from 1. Assume that the alphabet always consists of the lower case letters ’a’ to ’z’.

For instance, if the list only contains the combinations q, ab and aaa, the words would be
enumerated like this:
1. a
2. b
...
16. p
17. r
...
26. aa
27. ac
...
649. zz
650. aac
Given the list of letter combinations, write a program that for a given word outputs its number, and for a given number ouputs its word. You can assume that none of the words will exceed 20 characters and no number will be greater than 2 000 000 000 (for both input and output).

Input
The input will contain several test cases. The number of test cases T appears on a line by itself. Then follow T test cases. Each test case starts with a line containing two integers, N (the number of letter combinations, non-negative, at most 1 000) and M (the number of queries for this list, positive, at most 100). Then follow N lines, each containing a lower case letter combination (between 1 and 3 letters, inclusive). After that follow M lines, each containing either a positive integer or a lower case word. If it’s a word, it will not contain any of the combinations of letters in the list for this test case. If it’s a number, it will not be greater than the number of words in the language.

Output
For each query, output a single line containing either the word’s corresponding number, or the number’s corresponding word.

Sample Input
2
3 4
q
ab
aaa
16
r
27
aac
7 2
a
b
c
d
ef
ghi
ijk
102345678
ksvfuw

Sample Output
p
17
ac
650
xexgun
39174383

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

相似问题

2
一个c语言的算法循环问题
0
C语言数据结构的模拟银行存钱取钱的算法,采用C语言程序的编写
0
Galou is back! 类欧几里得算法 线段树方面的一个问题的思路求教,怎么利用C语言的编写实现
0
请教一个有关随机数生成算法方面的算法问题,利用C语言算法的实现的过程方式
0
树状节点的编号的一个算法的问题,看下怎么使用C语言编写程序来计算
0
一个和概率生成有关的算法问题,请教如何利用C语言的综合技术编写?
0
日期作为整数单独输入的计算的算法问题,利用C语言的办法如何解决
0
一个猜测单词的游戏的算法,利用C语言的方式是如何实现的呢
0
字母的排列构成的单词的算法的问题,是如何利用C语言的办法实现呢
1
子集序列的最大连续值问题的算法,如何利用C语言的方式编程来实现
0
矩阵数字的一个路径的算法,怎么利用C语言编写程序的方式实现的
0
石头分堆的问题的算法解决,如何利用C语言的程序设计的方式
0
广度优先遍历的路径搜索算法问题怎么解决?运用C语言的程序编写方式
0
摘苹果的算法应用问题,怎么利用C语言程序设计的办法来解决的
0
寻找存在的区间的整数的算法问题,怎么利用C语言程序的算法来实现的
0
纸牌牌面正反的判断问题的算法,怎么采用C语言程序设计的办法来实现的
0
寻找集合的非递减序列的算法,怎么利用C语言程序的设计办法来实现的
0
切分巧克力的算法的一个问题,怎么利用C语言的程序设计的办法?
1
因数质因数的分解的问题的算法怎么利用C语言的程序来实现的呢?
0
金币在篮子当中的分装的问题的算法,采用C语言程序的编写过程实现