编程介的小学生 2019-03-26 10:59 采纳率: 20.5%
浏览 168

英文单词的编码的算法问题,如何利用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

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥15 stable diffusion
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误