V
V
valent_in_habrahabr2014-10-06 17:19:59
C++ / C#
valent_in_habrahabr, 2014-10-06 17:19:59

What algorithm to apply?

Exercise

Implement

{
   
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
Forzenals Voteva, 2014-10-06
@captain_fistashka

For example:
Knuth-Morris-Pratt algorithm

A
AlexP11223, 2014-10-06
@AlexP11223

It's more like your C than C++.
And in C++ there is std::string with for example find method www.cplusplus.com/reference/string/string/find

return ri;
return -1;

Return -1 will never get there.

E
Eugene, 2014-10-06
@EvgenijDv

The simplest solution is this:
You loop through the source string and compare the current character with the first character in the Pattern. Once they match (let's say at position i), you loop over pattern and test str[i+offset] to be equal to the current character in pattern, where offset is the current offset in pattern. If any of the characters does not match, then you return to the first loop and continue working with the character str[i+1].

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question