You might have heard of Regular Expressions, but this question is about Irregular Expressions, a concept we just invented. An irregular expression is a pattern string that can be used to match target strings. Here's an example pattern that can be used to "accept" or "reject" target strings:
There are two rules for matching a target string to a pattern like the one above:
- Any lower case letter that is not inside square brackets in the pattern must match to the same letter in the target string, in the correct position.
- If a set of lower case letters appears in square brackets in the pattern, the target string must contain, at that point in the string, exactly half of these letters (rounded up) in any order.
There are lots of target strings that match the above pattern (~60~ to be precise). Here are a few of them. The parts that match the bracketed portion are highlighted:
adbskkkjbbb, adbskjkkbbb, adbskskfbbb, adbskfjkbbb
Of course there are also an infinite number of targets that do not match. Here are a few of them:
adbskkkjsbbb, adbskjkbbb, adbsjsvbbb, adbsksfjbb, fhfghj tomato pesto
An irregular expression can be any length, can use any plain lower case letter, and can contain zero or more non-nested square bracket sections.
The input will contain ~10~ lines. Each line will consist of an irregular expression pattern string followed by ~5~ target strings to match, all separated by spaces. Your program must output either
false for each target string depending on whether it matches the pattern. The words
false must be lower case and separated by a single space. You should produce a separate line of text for each line in the input. The maximum length for each pattern and each target string is ~256~ characters.
Note that the test data below has only ~5~ lines, but the real data file will have ~10~.
adbsk[kkjsvf]bbb adbskkkjbbb adbskkkjsbbb adbskskfbbb adbsjsvbbb fhfghj fkqm[qzqyledbqq]c fkqmdqqqlc fkqmqlbyq fkqmqedqc fkqmblqqzc fkqmlqbdzc dj[mocn]dd djnmdd djocdd djmodd djmodd djcndd wsvahfskbs[uucysmlfrcnhu]mjgphbd this problem is ridiculous dude a[aauzujbtipmca]bsk aiamzuausk acuaaujabsk aaaauucbsk aazpubtubsk aiaujcambsk
true false true false false true false false true true true true true true true false false false false false false true false true true
Educational Computing Organization of Ontario - statements, test data and other materials can be found at ecoocs.org