ls
InterviewTime limit1sMemory limit128 MB
Given a wildcard pattern where * matches any run of characters, print the input file names that match it, keeping input order.
- Level
Medium5 of 10
- Topics
- Dynamic programming, String, Brute force, Recursion
- Solved
- No attempts yet
Problem
Hyunjin is building a hobby operating system at home. Today it is time to implement ls, the command that lists the files inside a directory. Hyunjin wants users to be able to pick out only the file names that match a pattern by using the wildcard *.
The wildcard * matches zero or more of any character. Every other character in the pattern (lowercase letters and .) must match itself exactly.
Input
The first line contains a pattern P. P has a length between 1 and 100 characters and consists only of lowercase letters, ., and *.
The second line contains N, the number of files in the directory ().
Each of the next N lines contains one file name. Each file name has a length between 1 and 100 characters and consists only of lowercase letters and ..
Output
Print the names of the files that match pattern P, one per line, in the order they appear in the input. If no file matches, print nothing.