编程介的小学生 2017-03-29 10:22 采纳率: 20.5%
浏览 720
已采纳

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-04-07 14:52
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料