ANARC08C - Match Maker

no tags 

In Computer Science, pattern matching is the act of checking if a certain sequence conforms (matches) a given pattern. Patterns are usually specified using a language based on regular expression. In this problem, we'll use a simple regular expression to express patterns on sequences of decimal digits. A pattern is a sequence of one or more decimal digits '0' ...'9', asterisks '*', and hash signs '#'. A '*' denotes a sequence of an even number of digits, whereas a '#' denotes a sequence of an odd number of digits. For example, the pattern "129" only matches the sequence 129. The pattern "1*3" matches all sequences beginning with 1, ending with 3, and having an even number of decimal digits between the first and last digits. As another example, the pattern "#55" matches the sequences 155, 12355, 1234555, but none of the sequences 55, 1255, 123455. Your task is to write a program to find if a given sequence matches a given pattern.


Your program will be tested on one or more data sets. Each data set contains a single pattern and one or more sequences to match. The first line of each data set specifies the pattern, and the remaining lines specify the sequences to match against that pattern. The end of a data set (except the last) is identified by the word "END" (without the double quotes.) The end of the last data set is identified by the word "QUIT". All lines are 100,000 characters long or shorter.


k.s. result

Where k is the test case number (starting at one,) and s is the sequence number (starting at one within each test case,) and result is either the word "match" if the given string matches the pattern, or the word "not" if it doesn't.



1.1. not
1.2. match
1.3. not
2.1. not
2.2. match
3.1. match
3.2. match
3.3. not
3.4. not

hide comments
Balrog: 2010-03-11 13:31:27

when I use gets,I got runtime error too,after i use scanf,i got ac.
I think there must be some '\r' or other character in theend of the line
problemsetter should check the testdata (if your testdata generated in the windows or other something...),you should be responsible to your problem and testdata!

:D: 2010-03-04 13:13:26

Every combination of '0'-'9', '*' and '#' is a possible pattern, why wouldn't it be?

Last edit: 2010-03-04 13:13:49
:): 2010-02-01 18:16:21

is 123*123#123 possible as a test case??

watashi: 2009-08-27 14:16:38

When I use fgets to read the input data, I got runtime error (SIGABRT). After replacing them with scanf, I got ac. Why?

:D: 2009-08-21 19:09:45

'##' means (2n-1)+(2m-1)=2(n+m-1) digits for some positive integers n and m. So it's even, but it's not the same as '*' since it's always positive and '*' can mean 0 (at least that was the assumption I made in my AC code).

Ajay Nair: 2009-07-30 02:54:43

if in #55 denotes odd number of digits before 55, what about ##55 ? even digits ?

Added by:Ahmed Aly
Time limit:1.096s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:ANARC 2008