Editorial for ECOO '13 R3 P1 - Irregular Expressions


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

This problem is fairly straightforward but for most solutions, it will require carefully keeping track of where you are in each string using two indices. You also have to watch out for running out of characters in either the pattern or the target during the matching process and abort if that happens.

In my solution, when I encounter a bracket in the pattern, I read ahead to the next bracket and build a string of the n characters in the brackets. Then I look at the next n/2 characters in the target (rounding up) and for each one that appears in the string of characters I built, I remove that character from the list and continue. If I find a character that doesn't belong, I stop.

Test Cases

The sample data given in the question is very easy – the patterns are short and none of them contain more than one set of brackets. There is also a simple strategy that gets them all right – simply compute the correct length of a matching target string and accept any target string that is of the correct length. The real test data was constructed so that this strategy will fail on all but a couple of cases.

The test cases were also designed to test boundary cases. There were patterns that started with [, patterns that ended with ], patterns that contained adjacent brackets (e.g. [...][...]), and patterns with no brackets at all. Non-matching strings were also designed to cover a variety of cases that might cause problems.


Comments

There are no comments at the moment.