Input a list of strings a
and a string s
for search keyword. Find out all strings in a
which contains s
as subsequence. And sort them in the following order:
- Exactly equals to
s
- Starts with
s
- Contains
s
as substring (continuous subsequence) - Contains
s
as subsequence
Detail
- When two strings belongs to the same sorting group, you may sort them in any order you prefer.
- String matching is case sensitive. "A" and "a" are different characters.
- All strings will only contain printable ASCII (#32~#126).
- All strings will not have leading or trailing whitespaces.
- All strings will be non-empty.
- List
a
does not contain duplicate strings.
Example
When the list is ["center","encounter","enter","enterprise","event"]
, and the search target is "enter"
, output should be ["enter","enterprise","center","encounter"]
. "event"
is not included in the output as it doesn't contain "enter"
as subsequence.
Test cases
["center","encounter","enter","enterprise","event"]
"enter"
-> ["enter","enterprise","center","encounter"]
["celebration","cooperation","generation","operation","ratio"]
"ratio"
-> ["ratio","celebration","cooperation","generation","operation"]
["combination","explanation","international","nation","national","nomination","notation"]
"nation"
-> ["nation","national","combination","explanation","international","nomination","notation"]
["ever","every","here","very","where"]
"everywhere"
-> []
["interaction","traditional","train","training","transformation"]
"train"
-> ["train","training","interaction","traditional","transformation"]
["condition","confusion","construction","contribution","information","organization","recommendation","transportation"]
"onion"
-> ["condition","confusion","construction","contribution","organization","recommendation"]
["...","---",".-.-.-","..--","-..-"]
"--"
-> ["---","..--",".-.-.-","-..-"]
["#","##","###","####","#####"]
"####"
-> ["####","#####"]
["Another", "example", "with spaces", "and also", "question marks", "...??"]
"a"
-> ["and also", "example", "with spaces", "question marks"]
["/.\\", "...", "><", "[[]]", "~.~", ".1.2", "_[(("]
"."
-> ["...", ".1.2", "/.\\", "~.~"]
["(())", "()()", "((()))", "(())()", "()(())", "()()()"]
"(())"
-> ["(())", "(())()", "((()))", "()(())", "()()()"]
["]["]
"]["
-> ["]["]
["\\", "\\\\", "\\\\\\"] # Input is encoded as JSON, while "\\" means a string with a single backslash
"\\"
-> ["\\", "\\\\", "\\\\\\"]
Output from your program may be different from above test cases, as the order of words in same group is not required.
Rules
- This is code-golf, shortest code wins.
Input / Output
Input / Output are flexible. For example, you may use any reasonable ways including but not limited to:
- You may I/O
string
as- Your languages built-in
string
in ASCII or any ASCII compatible encoding (e.g. UTF-8); - Your languages built-in
string
in any codepage that supports all printable ASCII characters (e.g. UTF-16); - NUL terminated array of characters;
- array of integers, each integer is the ASCII value of character
- 0 terminated integer array;
- Your languages built-in
- You may I/O the array of
string
as- A collection (
OrderedSet
,LinkedList
,Array
, ...; orHashSet
only for input) ofstring
s - A character (or ASCII value) matrix with NUL (0) padding at the ending to each short ones;
- Output matrix may have unnecessarily extra 0 padding;
- Line break (CR / LF / CRLF) separated single string;
- JSON encoded array of string
- A collection (