###Substr finding algorithm : Sunday
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| int sunday(char SArrary[], int iSLen, char TArrary[], int iTLen) { int i = 0, j = 0, pos = -1; while (i < iSLen) { if (SArrary[i] == TArrary[j]) { ++i; ++j; if (j == iTLen - 1) { pos = i - j; } } else { int next = iTLen - j + i; int k = iTLen - 1; for (; k >= 0; --k) { if (SArrary[next] == TArrary[k]) { break; } } if (k >= 0) { i = next - k; } else { ++i; } j = 0; } }
return pos; }
|