0% found this document useful (0 votes)
33 views1 page

prob-I-Simple Regular Expression

The document describes a regular expression problem from the 2020 ICPC Vietnam Southern Provincial Programming Contest. Given a pattern P and string S, the problem is to count the number of cyclic shifts of S that match P, where a cyclic shift is splitting S into two non-empty parts and rotating them. The input consists of P and S, and the output is the number of matching cyclic shifts. Sample inputs and outputs are provided for testing.

Uploaded by

Thu Hằng
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views1 page

prob-I-Simple Regular Expression

The document describes a regular expression problem from the 2020 ICPC Vietnam Southern Provincial Programming Contest. Given a pattern P and string S, the problem is to count the number of cyclic shifts of S that match P, where a cyclic shift is splitting S into two non-empty parts and rotating them. The input consists of P and S, and the output is the number of matching cyclic shifts. Sample inputs and outputs are provided for testing.

Uploaded by

Thu Hằng
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

The 2020 ICPC Vietnam Southern Provincial

Programming Contest
University of Science, VNU-HCM
October 25, 2020

Problem I
Simple Regular Expression
Time Limit: 1 second
Memory Limit: 64 megabytes
Mr. Do Le is learning about regular expression. He has just learned about
the notation “*” (star). This character can be used for representing any
string including an empty string.
Mr. Do Le considers that a string 𝑻 matches a pattern 𝑷 if and only if
there is a way to replace the stars in 𝑷 with (possibly empty) sequences
of lowercase letters so that the result equals 𝑻. For example, the string
aadbc matches the pattern a*b*c, as we can obtain the string from the
pattern by replacing the first star in the pattern with ad and the second one with the empty string.
On the other hand, the string abcbcb does not match this pattern.
Given a non-empty string 𝑺, Mr. Do Le wants to know the number of cyclic shifts of 𝑺 that
match the given pattern 𝑷.
Note: The cyclic shift is defined as the string S can be split into two non-empty parts X + Y and
in one operation we can transform S to Y + X from X + Y.

Input
The first line of input contains the pattern 𝑃 (no more than 100 characters).
The second line contains the string 𝑆 (no more than 105 characters).

Output
The output consists of a single integer, the number of cyclic shifts of 𝑆 that match the pattern 𝑃.

Sample Input Sample Output


aaaa 4
aaaa
a*a 6
aaaaaa
*a*b*c* 15
abacabadabacaba

12

You might also like