Please, try EDU on Codeforces! New educational section with videos, subtitles, texts, and problems. ×

Need help on a problem- SPOJ CPATTERN

Revision en1, by saurabhs1206, 2019-07-08 11:18:39

I have been trying to solve the problem CPATTERN from SPOJ. Link: https://www.spoj.com/problems/CPATTERN/.

I store the input sequence in text[] and subgroup sequence in pattern[]. Using text[], I created another array diffText[] that stores:

diffText[i] = 1 if text[i - 1] > text[i],
diffText[i] = 0 if text[i - 1] == text[i],
diffText[i] = -1 if text[i - 1] < text[i]

In the same way, I construct the array diffPattern[] for pattern[]. Then I use KMP to search for the diffPattern[] in diffText[]. It shows wrong answer. Is this incorrect approach? Please help.

Tags solution spoj, #spoj, #string matching, kmp

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English saurabhs1206 2019-07-08 11:18:39 671 Initial revision (published)