.


:




:

































 

 

 

 


( Thierry Lecroq )




, - , , , ,

ASCII , . .

ϳ x y [i, i + m-1], - 1. , y [i + m] ' , , . , :

bc [a] = min {j | 0 j m x [m - 1 - j] = a}, a x,

bc [a] = m .

- .

( Thierry Lecroq).

- - . ' , ( , ).

:

1.

2. -

- , , , , , , ' .

u - , v - c, , uzv - x. av - x, b p , x | uzv | p, b . | u | - | v | ( - ).

-

- . - . - - .

0 255. , - ( ), - , , , -, . ' , -, "" .

 

.

 

#include<iostream>

#include<string.h>

using namespace std;

int NSN(char *x, char *y, int n, int m)

{

int i, k, l;

char secondch, firstch, *thirdch;

if (x[ 0 ] == x[ 1 ])

{

k = 2;

l = 1;

}

else

{

k = 1;

l = 2;

}

/* Searching */

i = 0;

firstch = x[ 0 ];

secondch = x[ 1 ];

thirdch = &x[ 2 ];

while (i <= n - m)

{

cout<<"i="<< i<<endl;

if (y[ i + 1 ]!= secondch) i+=k;

else {

cout<<"Maybe in i="<< i<<endl;

//cout<<memcmp(&y[ i + 2 ], thirdch, m - 2);

if (memcmp(&y[ i + 2 ], thirdch, m - 2) == 0

&& y[ i ] == firstch)

{

cout<<"Exacly in i="<<i<<endl;

return i;

}

}

}

return -1;

}

int main()

{

char str[300];

char sub[300];

string s,s_find;

cin.getline(str,256);

cin.getline(sub,256);

int l,l_find;

l=strlen(str);

l_find=strlen(sub);

cout<<"l="<<l<<endl;

cout<<"l_find="<<l_find<<endl;

int result = NSN(sub,str,l,l_find);

if(result==-1)cout<<"Nema takoji pidstrichki\n";

else cout<<"Pidstrichka pochinajetsa z #="<<result+1<<"\n";

system("pause");

return 0;

}

 

: . .

 





:


: 2016-11-02; !; : 293 |


:

:

.
==> ...

1495 - | 1485 -


© 2015-2024 lektsii.org - -

: 0.013 .