编程介的小学生 2017-08-30 14:49 采纳率: 20.5%
浏览 757
已采纳

Z Shell Completion

As a Linux user, Whistler has tried several command-line shells. Among these shells, he likes the Z Shell('ZSH' for short) best because ZSH provides more amazing features.

Command-line shells usually provide some completion feature. For example, in the directory '/home/whistler', there is only a file named 'document'. Then you can type '/home/whistler/d' and press [TAB] to let the shell complete the word 'document'.

ZSH makes completion more enjoyable, especially for lazy guys. Completion in ZSH can be done using first several letters in each directory. Consider the same situation above, '/home/whistler/document' could be completed using '/h/wh/d' and a single [TAB], if there are no other files or directories with a full path of '/h*/wh*/d*'.

Unfortunately, there is no ZSH on a remote system used by Whistler. And Whistler does not have enough permission to install ZSH on that system. So he asks you to implement a simple completion program.

To simplify the problem, there are several assumptions:

The names of directories and files only contain these characters: lower-case letters, numbers and '.'
The minimum and maximum allowed length of a directory name or a file name are 1 and 32
The directory separator is '/'
No more than 11 '/' in the full path of any file
Users will give full paths (that is, always start from root with a '/', no relative location)
Users may give full path to a directory or a file and no '/' at the end of any full path (for example, '/h/wh' can be completed to '/home/whistler')
Input

This problem contains multi test cases (no more than 4). Please proceed to the end of input.

The 1st line only contains an integer N (0 <= N <= 10000).

Following N lines are full paths of directories or files, one per line. It is guaranteed that full path of a directory occurs before files or directories it contains occur. (that is, '/blabla' occurs before any '/blabla/foo' occurs, where 'blabla' may contain one or more '/')

The N+2 line only contains an integer M (0 <= M <= 30000).

Following M lines are inputs by users, one per line.

There is a blank line after each test case.

Note that the largest test case is generated randomly, not from an existing file system.

Output

For each user input, if there is a unique completion, output that completion in one line, without tailing '/'. When there is more than one way or no way to complete, output an integer, which is the count of possible completions in one line.

Sample Input

5
/usr
/usr/local
/home
/home/whistler
/home/who
5
/u
/home
/u/loc
/ho/w
/bin

Sample Output

/usr
/home
/usr/local
2
0

  • 写回答

1条回答 默认 最新

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

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法