编程介的小学生 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
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退