编程介的小学生 2017-08-24 10:16 采纳率: 0.2%
浏览 550
已采纳

Auto Spell Corrector

Have you ever used Microsoft Word (R) to edit English document? Have you noticed the auto-spell-corrector?

Littleboy found that whenever he mistypes the "the" as "teh" or "hte", it will be corrected automatically. Littleboy noticed that people are prone to typing the characters out of order when they type too fast, and he guesses that auto-spell-corrector in Microsoft Word (R) relies on this fact. Being interested in this, he decided to write a simple auto-spell-corrector of his own.

His algorithm works as follow: given a word,

  1. If the word can be found from the predefined dictionary, left it as it was.
  2. If swapping one pair of consecutive characters leads to another word that can be found from the predefined dictionary, that word is an option for substitution. If one or more substitution candidates were found, output all of them.
  3. If neither of the above schemes can be applied to the word, it must be a name, so left it as it was.

Input

Input consists of multiple test cases. The first line of the input will be a positive number T(0<T<=10), representing the number of the test cases. Then follow T test cases.

The first line of each test case, there will be an integer D(0<=D<=100), the number of the words in the predefined dictionary. Then D words follow, each word in its own line. After the predefined dictionary, there will be an integer Q(0<=Q<=100), the number of the words that littleboy typed. Again, follow Q words, each in its own line. The length of the word(both in predefined dictionary and littleboy typed) is between 1 and 20, inclusive. All words will only consist of lower case letters ('a'..'z').

Output

For each word littleboy typed, output all the substitution candidates(or the word as it was, depending on which scheme the word matches) in one line, sorted by lexicographically ascending order and separated by a comma(','). So for each testcase, there will be Q lines of output.

Separate two consecutive test cases with a blank line, but Do NOT output an extra blank line after the last one.

Sample Input

2
1
the
3
the
teh
hte
6
acbed
acbde
abdce
abced
badce
bcade
3
acbde
abcde
smith
Sample Output

the
the
the

acbde
abced,abdce,acbde
smith

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-09-06 00:39
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决
  • ¥15 请问维特智能的安卓APP在手机上存储传感器数据后,如何找到它的存储路径?