{"id":255,"date":"2012-11-12T14:01:00","date_gmt":"2012-11-12T06:01:00","guid":{"rendered":"http:\/\/nike0good.jp1.rpvhost.net\/160"},"modified":"2012-11-12T14:01:00","modified_gmt":"2012-11-12T06:01:00","slug":"kmp","status":"publish","type":"post","link":"https:\/\/nike0good.com\/?p=255","title":{"rendered":"KMP"},"content":{"rendered":"<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n\u4f5c\u8005\uff1aJuly\u3002<br \/>\n\u51fa\u5904\uff1a<a href=\"http:\/\/blog.csdn.net\/v_JULY_v\/\" target=\"_blank\" style=\"color:rgb(51,102,153); text-decoration:none\" rel=\"noopener\">http:\/\/blog.csdn.net\/v_JULY_v\/<\/a>\u3002\n<\/p>\n<h3 class=\"Section0\" style=\"margin:0px; padding:0px; color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left\">\n<a name=\"t0\" style=\"color:rgb(51,102,153)\"><\/a>\u5f15\u8bb0<\/h3>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; \u6b64\u524d\u4e00\u5929\uff0c\u4e00\u4f4dMS\u7684\u670b\u53cb\u9080\u6211\u4e00\u8d77\u53bb\u4e0e\u4ed6\u8ba8\u8bba\u5feb\u901f\u6392\u5e8f\uff0c\u7ea2\u9ed1\u6811\uff0c\u5b57\u5178\u6811\uff0cB<span style=\"font-family:\u5b8b\u4f53\">\u6811\u3001\u540e\u7f00\u6811\uff0c\u5305\u62ec<\/span>KMP<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\uff0c\u552f\u72ec\u5728\u8bb2\u89e3<\/span>KMP<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u7684\u65f6\u5019\uff0c\u8a00\u8bed\u78d5\u78d5\u78b0\u78b0\uff0c\u6211\u60f3\uff0c\u539f\u56e0\u6709\u4e8c\uff1a<\/span>1<span style=\"font-family:\u5b8b\u4f53\">\u3001\u535a\u5ba2\u5185\u7684\u4e1c\u897f\u4e0d\u5e38\u56de\u987e\uff0c\u5fd8\u4e86\u4e0d\u5c11\uff1b<\/span>2<span style=\"font-family:\u5b8b\u4f53\">\u3001\u4fbf\u662f\u6211\u5bf9<\/span>KMP<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u7684\u7406\u89e3\u8fd8\u4e0d\u591f\u5f7b\u5e95\uff0c\u81ea\u4e0d\u7528\u8bf4\u8bb2\u89e3\u81ea\u5982\uff0c\u8fd0\u7528\u81ea\u5982\u4e86\u3002\u6240\u4ee5\uff0c\u7279\u518d\u5199\u672c\u7bc7\u6587\u7ae0\u3002\u7531\u4e8e\u6b64\u524d\uff0c\u4e2a\u4eba\u5df2\u7ecf\u5199\u8fc7\u5173\u4e8e<\/span>KMP<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u7684\u4e24\u7bc7\u6587\u7ae0\uff0c\u6240\u4ee5\uff0c\u672c\u6587\u540d\u4e3a\uff1a<\/span>KMP<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u4e4b\u603b\u7ed3\u7bc7\u3002<\/span><\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp; &nbsp;\u672c\u6587\u5206\u4e3a\u5982\u4e0b\u516d\u4e2a\u90e8\u5206\uff1a<\/p>\n<ol style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<li>\u7b2c\u4e00\u90e8\u5206\u3001\u518d\u6b21\u56de\u987e\u666e\u901a\u7684BF<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u4e0e<\/span>KMP<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u5404\u81ea\u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u5e76\u4e24\u76f8\u5bf9\u7167\u5404\u81ea\u7684\u5339\u914d\u539f\u7406\uff1b<\/span><\/li>\n<li><span style=\"font-family:\u5b8b\u4f53\">\u7b2c\u4e8c\u90e8\u5206\u3001\u901a\u8fc7\u6211\u6b64\u524d\u7b2c\u4e8c\u7bc7\u6587\u7ae0\u7684\u5f15\u7528\uff0c\u7528\u56fe\u4ece\u5934\u5230\u5c3e\u8be6\u7ec6\u9610\u8ff0<\/span>KMP<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u4e2d\u7684<\/span>next<span style=\"font-family:\u5b8b\u4f53\">\u6570\u7ec4\u6c42\u6cd5\uff0c\u5e76\u8fd0\u7528\u6c42\u5f97\u7684<\/span>next<span style=\"font-family:\u5b8b\u4f53\">\u6570\u7ec4\u5199\u51fa<\/span>KMP<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u7684\u6e90\u7801\uff1b<\/span><\/li>\n<li><span style=\"font-family:\u5b8b\u4f53\">\u7b2c\u4e09\u90e8\u5206\u3001KMP\u7b97\u6cd5\u7684\u4e24\u79cd\u5b9e\u73b0\uff0c\u4ee3\u7801\u5b9e\u73b0\u4e00\u662f\u6839\u636e\u672c\u4eba\u5173\u4e8eKMP\u7b97\u6cd5\u7684\u7b2c\u4e8c\u7bc7\u6587\u7ae0\u6240\u5199\uff0c\u4ee3\u7801\u5b9e\u73b0\u4e8c\u662f\u6839\u636e\u672c\u4eba\u7684\u5173\u4e8eKMP\u7b97\u6cd5\u7684\u7b2c\u4e00\u7bc7\u6587\u7ae0\u6240\u5199\uff1b<\/span><\/li>\n<li><span style=\"font-family:\u5b8b\u4f53\">\u7b2c\u56db\u90e8\u5206\u3001\u6d4b\u8bd5\uff0c\u5206\u522b\u5bf9\u7b2c\u4e09\u90e8\u5206\u7684\u4e24\u79cd\u5b9e\u73b0\u4e2dnext\u6570\u7ec4\u7684\u6c42\u6cd5\u8fdb\u884c\u6d4b\u8bd5\uff0c\u6316\u6398\u5176\u533a\u522b\u4e4b\u6240\u5728\uff1b<\/span><\/li>\n<li><span style=\"font-family:\u5b8b\u4f53\">\u7b2c\u4e94\u90e8\u5206\u3001KMP\u5b8c\u6574\u51c6\u786e\u6e90\u7801\uff0c\u7ed9\u51faKMP\u7b97\u6cd5\u7684\u51c6\u786e\u7684\u5b8c\u6574\u6e90\u7801\uff1b<\/span><\/li>\n<li><span style=\"font-family:\u5b8b\u4f53\">\u7b2c\u516d\u6b65\u4efd\u3001\u4e00&#30524;\u770b\u51fa\u5b57\u7b26\u4e32\u7684next\u6570\u7ec4\u5404&#20540;\uff0c\u901a\u8fc7\u51e0\u4e2a\u4f8b\u5b50\uff0c\u8ba9\u8bfb\u8005\u80fd\u6839\u636e\u5b57\u7b26\u4e32\u672c\u8eab\u4e00&#30524;\u5224\u65ad\u51fa\u5176next\u6570\u7ec4\u5404&#20540;\u3002<\/span><\/li>\n<\/ol>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<span style=\"font-family:\u5b8b\u4f53\">&nbsp; &nbsp; \u529b\u6c42\u8ba9\u6b64\u6587\u5f7b\u5e95\u8ba9\u8bfb\u8005\u6d1e\u7a7f\u6b64<\/span>KMP<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\uff0c\u6240\u6709\u539f\u7406\uff0c\u6765\u9f99\u53bb\u8109\uff0c\u8ba9\u8bfb\u8005\u641e\u4e2a\u901a\u901a\u900f\u900f\uff08\u6ce8\u610f\uff0c\u672c\u6587\u4e2d\u7b2c\u4e8c\u90e8\u5206\u53ca\u7b2c\u4e09\u90e8\u5206\u7684\u4ee3\u7801\u5b9e\u73b0\u4e00\u7684\u5b57\u7b26\u4e32\u4e0b\u6807i \u4ece<span style=\"font-family:Arial\">0<\/span>\u5f00\u59cb\u8ba1\u7b97\uff0c\u5176\u5b83\u90e8\u5206\u5982\u7b2c\u4e09\u90e8\u5206\u7684\u4ee3\u7801\u5b9e\u73b0\u4e8c\uff0c\u7b2c\u4e94\u90e8\u5206\uff0c\u548c\u7b2c\u516d\u90e8\u5206\u7684\u5b57\u7b26\u4e32\u4e0b\u6807i \u7686\u662f\u4ece1\u5f00\u59cb\u7684\uff09\u3002<\/span><\/p>\n<p><span style=\"color:rgb(51,51,51); font-size:14px; line-height:26px; text-align:left; font-family:\u5b8b\u4f53\"><\/span><span style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\"><\/span><\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; \u5728\u770b\u672c\u6587\u4e4b\u524d\uff0c\u4f60\u5fc3\u4e2d\u5982\u82e5\u5bf9\u524d\u7f00\u548c\u540e\u7f00\u8fd9\u4e2a\u4e24\u4e2a\u6982\u5ff5\u6709\u81ea\u5df1\u7684\u7406\u89e3\uff0c\u4fbf\u6700\u597d\u4e86\u3002\u6709\u4e9b\u4e1c\u897f\u6bd4\u5982\u6b64KMP<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u9700\u8981\u6211\u4eec\u53cd\u590d\u601d\u8003\uff0c\u53cd\u590d\u6c42\u89e3\u624d\u884c\u3002\u4e2a\u4eba\u5199\u7684\u5173\u4e8eKMP\u7b97\u6cd5\u7684\u7b2c\u4e8c\u7bc7\u6587\u7ae0\u4e3a\uff1a<a href=\"http:\/\/blog.csdn.net\/v_JULY_v\/archive\/2011\/06\/15\/6545192.aspx\" target=\"_blank\" style=\"color:rgb(34,0,0); text-decoration:none; font-family:Arial\" rel=\"noopener\">\u516d\uff08\u7eed\uff09\u3001\u4eceKMP\u7b97\u6cd5\u4e00\u6b65\u4e00\u6b65\u8c08\u5230BM\u7b97\u6cd5<\/a><\/span>\uff1b\u7b2c\u4e00\u7bc7\u4e3a\uff1a\u516d\u3001\u6559\u4f60\u521d\u6b65\u4e86\u89e3KMP\u7b97\u6cd5\u3001updated\uff08\u6587\u672b\u94fe\u63a5\uff09\u3002ok<span style=\"font-family:\u5b8b\u4f53\">\uff0c\u82e5\u6709\u4efb\u4f55\u95ee\u9898\uff0c\u6073\u8bf7\u4e0d\u541d\u6307\u6b63\u3002\u591a\u8c22\u3002<\/span><\/p>\n<h3 class=\"Section0\" style=\"margin:0px; padding:0px; color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left\">\n<a name=\"t1\" style=\"color:rgb(51,102,153)\"><\/a>\u7b2c\u4e00\u90e8\u5206\u3001KMP<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u521d\u89e3<\/span><\/h3>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<strong>1<span style=\"font-family:\u5b8b\u4f53\">\u3001<\/span>\u666e\u901a\u5b57\u7b26\u4e32\u5339\u914dBF<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u4e0e<\/span>KMP<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u6bd4\u8f83<\/span><\/strong><\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; KMP<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u662f\u4e00\u79cd\u7ebf\u6027\u65f6\u95f4\u590d\u6742\u7684\u5b57\u7b26\u4e32\u5339\u914d\u7b97\u6cd5\uff0c\u5b83\u662f\u5bf9<\/span>BF<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\uff08<\/span>Brute-Force<span style=\"font-family:\u5b8b\u4f53\">\uff0c\u6700\u57fa\u672c\u7684\u5b57\u7b26\u4e32\u5339\u914d\u7b97\u6cd5\u7684\uff09\u6539\u8fdb\u3002\u5bf9\u4e8e\u7ed9\u7684\u539f\u59cb\u4e32<\/span>S<span style=\"font-family:\u5b8b\u4f53\">\u548c\u6a21\u5f0f\u4e32<\/span>P<span style=\"font-family:\u5b8b\u4f53\">\uff0c\u9700\u8981\u4ece\u5b57\u7b26\u4e32<\/span>S<span style=\"font-family:\u5b8b\u4f53\">\u4e2d\u627e\u5230\u5b57\u7b26\u4e32<\/span>P<span style=\"font-family:\u5b8b\u4f53\">\u51fa\u73b0\u7684\u4f4d\u7f6e\u7684\u7d22\u5f15\u3002<\/span><\/p>\n<blockquote style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left; margin:0px 0px 0px 40px; padding:0px\">\n<div class=\"Section0\">\n<p>BF<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6<\/span>O(strlen(S) * strlen(T))<span style=\"font-family:\u5b8b\u4f53\">\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6<\/span>O(1)<span style=\"font-family:\u5b8b\u4f53\">\u3002<\/span><\/p>\n<\/div>\n<\/blockquote>\n<blockquote style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left; margin:0px 0px 0px 40px; padding:0px\">\n<div class=\"Section0\">\n<p>KMP<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6<\/span>O(strlen(S) &#43; strlen(T))<span style=\"font-family:\u5b8b\u4f53\">\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6<\/span>O(strlen(T))<span style=\"font-family:\u5b8b\u4f53\">\u3002<\/span><\/p>\n<\/div>\n<\/blockquote>\n<div class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<p><strong>2<span style=\"font-family:\u5b8b\u4f53\">\u3001<\/span>BF<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u4e0e<\/span>KMP<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u7684\u533a\u522b<\/span><\/strong><\/p>\n<p>&nbsp;&nbsp;&nbsp; \u5047\u8bbe\u73b0\u5728S<span style=\"font-family:\u5b8b\u4f53\">\u4e32\u5339\u914d\u5230<\/span>i<span style=\"font-family:\u5b8b\u4f53\">\u4f4d\u7f6e\uff0c<\/span>T<span style=\"font-family:\u5b8b\u4f53\">\u4e32\u5339\u914d\u5230<\/span>j<span style=\"font-family:\u5b8b\u4f53\">\u4f4d\u7f6e\u3002\u90a3\u4e48\u603b\u7684\u6765\u8bf4\uff0c\u4e24\u79cd\u7b97\u6cd5\u7684\u4e3b\u8981\u533a\u522b\u5728\u4e8e\u5931\u914d\u7684\u60c5\u51b5\u4e0b\uff0c\u5bf9<\/span><img decoding=\"async\" alt=\"[j]\" src=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/other_site\/img_t_newj_org.gif\" style=\"border:none\" \/><span style=\"font-family:\u5b8b\u4f53\">\u7684&#20540;\u505a\u7684\u5904\u7406<\/span><span style=\"font-family:\u5b8b\u4f53\">\uff1a<\/span><\/p>\n<p>&nbsp;&nbsp; BF<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u4e2d\uff0c\u5982\u679c\u5f53\u524d\u5b57\u7b26\u5339\u914d\u6210\u529f\uff0c\u5373<\/span>s[i&#43;j] == T[j]<span style=\"font-family:\u5b8b\u4f53\">\uff0c\u4ee4<\/span>j&#43;&#43;<span style=\"font-family:\u5b8b\u4f53\">\uff0c\u7ee7\u7eed\u5339\u914d\u4e0b\u4e00\u4e2a\u5b57\u7b26\uff1b\u5982\u679c\u5931\u914d\uff0c\u5373<\/span>S[i &#43; j] != T[j]<span style=\"font-family:\u5b8b\u4f53\">\uff0c<strong>\u9700\u8981\u8ba9<\/strong><\/span><strong>i&#43;&#43;,<span style=\"font-family:\u5b8b\u4f53\">\u5e76\u4e14<\/span>j=<br \/>\n 0<\/strong><span style=\"font-family:\u5b8b\u4f53\">\uff0c\u5373\u6bcf\u6b21\u5339\u914d\u5931\u8d25\u7684\u60c5\u51b5\u4e0b\uff0c\u6a21\u5f0f\u4e32<\/span>T<span style=\"font-family:\u5b8b\u4f53\">\u76f8\u5bf9\u4e8e\u539f\u59cb\u4e32<\/span>S<span style=\"font-family:\u5b8b\u4f53\">\u5411\u53f3\u79fb\u52a8\u4e86\u4e00\u4f4d\u3002<\/span><\/p>\n<p>&nbsp;&nbsp;&nbsp; \u800cKMP<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u4e2d\uff0c\u5982\u679c\u5f53\u524d\u5b57\u7b26\u5339\u914d\u6210\u529f\uff0c\u5373<\/span>S[i]==T[j]<span style=\"font-family:\u5b8b\u4f53\">\uff0c\u4ee4<\/span>i&#43;&#43;<span style=\"font-family:\u5b8b\u4f53\">\uff0c<\/span>j&#43;&#43;<span style=\"font-family:\u5b8b\u4f53\">\uff0c\u7ee7\u7eed\u5339\u914d\u4e0b\u4e00\u4e2a\u5b57\u7b26\uff1b\u5982\u679c<\/span>\u5339\u914d\u5931\u8d25\uff0c\u5373S[i] != T[j]<span style=\"font-family:\u5b8b\u4f53\">\uff0c\u9700\u8981\u4fdd\u6301<\/span>i<span style=\"font-family:\u5b8b\u4f53\">\u4e0d\u53d8\uff0c\u5e76\u4e14\u8ba9<\/span>j<br \/>\n = next[j]<span style=\"font-family:\u5b8b\u4f53\">\uff0c\u8fd9\u91cc<\/span>next[j] &lt;=j -1<span style=\"font-family:\u5b8b\u4f53\">\uff0c\u5373\u6a21\u5f0f\u4e32<\/span>T<span style=\"font-family:\u5b8b\u4f53\">\u76f8\u5bf9\u4e8e\u539f\u59cb\u4e32<\/span>S<span style=\"font-family:\u5b8b\u4f53\">\u5411\u53f3\u79fb\u52a8\u4e86\u81f3\u5c11<\/span>1<span style=\"font-family:\u5b8b\u4f53\">\u4f4d<\/span>(<span style=\"font-family:\u5b8b\u4f53\"><strong>\u79fb\u52a8\u7684\u5b9e\u9645\u4f4d\u6570<\/strong><\/span><strong>j<br \/>\n - next[j]&nbsp; &gt;=1<\/strong>),<\/p>\n<p>&nbsp;&nbsp;&nbsp; \u540c\u65f6\u79fb\u52a8\u4e4b\u540e\uff0c<u>i<span style=\"font-family:\u5b8b\u4f53\">\u4e4b\u524d\u7684\u90e8\u5206\uff08\u5373<\/span>S[i-j&#43;1 ~ i-1]<span style=\"font-family:\u5b8b\u4f53\">\uff09\uff0c\u548c<\/span>j=next[j]<span style=\"font-family:\u5b8b\u4f53\">\u4e4b\u524d\u7684\u90e8\u5206\uff08\u5373<\/span>T[0 ~ j-2]<\/u><span style=\"font-family:\u5b8b\u4f53\"><u>\uff09\u4ecd\u7136\u76f8\u7b49<\/u>\u3002\u663e\u7136\uff0c\u76f8\u5bf9\u4e8e<\/span>BF<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u6765\u8bf4\uff0c<\/span>KMP<span style=\"font-family:\u5b8b\u4f53\">\u79fb\u52a8\u66f4\u591a\u7684\u4f4d\u6570\uff0c\u8d77\u5230\u4e86\u4e00\u4e2a\u52a0\u901f\u7684\u4f5c\u7528\uff01&nbsp;<\/span>(<span style=\"font-family:\u5b8b\u4f53\">\u5931\u914d\u7684\u7279\u6b8a\u60c5\u5f62\uff0c\u4ee4<\/span>j=next[j]<span style=\"font-family:\u5b8b\u4f53\">\u5bfc\u81f4<\/span>j==0<span style=\"font-family:\u5b8b\u4f53\">\u7684\u65f6\u5019\uff0c\u9700\u8981\u5c06<\/span>i<br \/>\n &#43;&#43;\uff0c\u5426\u5219\u6b64\u65f6\u6ca1\u6709\u79fb\u52a8\u6a21\u5f0f\u4e32)<span style=\"font-family:\u5b8b\u4f53\">\u3002<\/span>\n<\/p>\n<p><strong>3\u3001BF<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u4e3a\u4ec0\u4e48\u8981\u56de\u6eaf<\/span><\/strong><\/p>\n<\/div>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n\u9996\u5148\u8bf4\u4e00\u4e0b\u4e3a\u4ec0\u4e48BF<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u8981\u56de\u6eaf\u3002\u5982\u4e0b\u4e24\u5b57\u7b26\u4e32\u5339\u914d\uff08\u6070\u5982\u4e0a\u9762\u6240\u8ff0\uff1aBF\u7b97\u6cd5\u4e2d\uff0c\u5982\u679c\u5f53\u524d\u5b57\u7b26\u5339\u914d\u6210\u529f\uff0c\u5373<span style=\"font-family:Arial\">s[i&#43;j] == T[j]<\/span>\uff0c\u4ee4<span style=\"font-family:Arial\">j&#43;&#43;<\/span>\uff0c\u7ee7\u7eed\u5339\u914d\u4e0b\u4e00\u4e2a\u5b57\u7b26\uff09\uff1a<\/span><\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<span style=\"white-space:pre\"><\/span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i&#43;j<span style=\"font-family:\u5b8b\u4f53\">\uff08<\/span>j<span style=\"font-family:\u5b8b\u4f53\">\u968f<\/span>T<span style=\"font-family:\u5b8b\u4f53\">\u4e2d\u7684<\/span>j&#43;&#43;<span style=\"font-family:\u5b8b\u4f53\">\u53d8\uff0c\u800c\u52a8\uff09<\/span><\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<span style=\"white-space:pre\"><\/span>S\uff1aaaa<span style=\"color:rgb(204,0,0)\">a<\/span>cefghij<\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp;<span style=\"white-space:pre\"><\/span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; j&#43;&#43;<\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<span style=\"white-space:pre\"><\/span>T\uff1aaaa<span style=\"color:rgb(204,0,0)\">c<\/span>&nbsp;<\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n\u5982\u679c\u4e0d\u56de\u6eaf\u7684\u8bdd\u5c31\u662f\u4ece\u4e0b\u4e00\u4f4d\u5f00\u59cb\u6bd4\u8d77\uff1a<\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<span style=\"white-space:pre\"><\/span>aaaa<span style=\"color:rgb(204,0,0)\">c<\/span>efghij<\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<span style=\"white-space:pre\"><\/span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color:rgb(204,0,0)\">a<\/span>aac<\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n\u770b\u5230\u4e0a\u9762\u7ea2\u989c\u8272\u7684\u6ca1\uff0c\u5982\u679c\u4e0d\u56de\u6eaf\u7684\u8bdd\uff0c\u90a3\u4e48\u4ecea&nbsp;<span style=\"font-family:\u5b8b\u4f53\">\u7684\u4e0b\u4e00\u4f4d<\/span>c&nbsp;<span style=\"font-family:\u5b8b\u4f53\">\u6bd4\u8d77\u3002\u7136\u800c\u4e0b\u8ff0\u8fd9\u79cd\u60c5\u51b5\u5c31\u6f0f\u4e86\uff08\u6b63\u786e\u7684\u505a\u6cd5\u5f53\u7136\u662f\u8981\u56de\u6eaf\uff1a\u5982\u679c\u5931\u914d\uff0c\u5373<span style=\"font-family:Arial\">S[i &#43; j] != T[j]<\/span>\uff0c<strong>\u9700\u8981\u8ba9<\/strong><span style=\"font-family:Arial\">i&#43;&#43;,<span style=\"font-family:\u5b8b\u4f53\">\u5e76\u4e14<\/span>j=<br \/>\n 0<\/span>\uff09\uff1a<\/span><\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<span style=\"white-space:pre\"><\/span>a<u>aaac<\/u>efghij<\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<span style=\"white-space:pre\"><\/span>&nbsp;&nbsp;<span style=\"color:rgb(204,0,0)\">aaac<\/span><\/p>\n<div class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<p>&nbsp;&nbsp;&nbsp; \u6240\u4ee5\uff0cBF\u7b97\u6cd5\u8981\u56de\u6eaf\uff0c\u5176\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<div class=\"dp-highlighter bg_cpp\" style=\"font-family:Consolas,'Courier New',Courier,mono,serif; font-size:12px; background-color:rgb(231,229,220); width:687px; overflow:auto; margin:18px 0px!important; padding-top:1px\">\n<div class=\"bar\" style=\"padding-left:45px\">\n<div class=\"tools\" style=\"padding:3px 8px 10px 10px; font-size:9px; line-height:normal; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; color:silver; background-color:rgb(248,248,248); border-left-width:3px; border-left-style:solid; border-left-color:rgb(153,153,153)\">\n<a href=\"http:\/\/blog.csdn.net\/v_july_v\/article\/details\/7041827#\" class=\"ViewSource\" title=\"view plain\" style=\"color:rgb(160,160,160); text-decoration:none; background-color:inherit; border:none; padding:0px; margin:0px 10px 0px 0px; font-size:9px\">view plain<\/a><\/div>\n<\/div>\n<ol class=\"dp-cpp\" start=\"1\" style=\"margin:0px 0px 1px 45px!important; padding:0px; border:none; list-style-position:initial; background-color:rgb(255,255,255); color:rgb(92,92,92)\">\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;Index(SString&nbsp;S,&nbsp;SString&nbsp;T,&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;pos)&nbsp;{&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;<span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u8fd4\u56deT\u5728S\u4e2d\u7b2cpos\u4e2a\u5b57\u7b26\u4e4b\u540e\u7684\u4f4d\u7f6e<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;i=pos;&nbsp;j=1;k=0;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">while<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;(&nbsp;i&lt;&nbsp;=&nbsp;S[0]&nbsp;&amp;&amp;&nbsp;j&lt;&nbsp;=&nbsp;T[0]&nbsp;)&nbsp;{&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">if<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;(S[i&#43;k]&nbsp;=&nbsp;=&nbsp;T[j]&nbsp;)&nbsp;{&#43;&#43;k;&nbsp;&nbsp;&#43;&#43;j;}&nbsp;&nbsp;&nbsp;<\/span><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u7ee7\u7eed\u6bd4\u8f83\u540e\u7eed\u5b57\u7b26<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">else<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;{i=i&#43;1;&nbsp;&nbsp;&nbsp;j=1;&nbsp;k=0;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u6307\u9488\u56de\u6eaf\u5230&nbsp;\u4e0b\u4e00\u9996\u4f4d\uff0c\u91cd\u65b0\u5f00\u59cb<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;}&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">if<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">(j&gt;T[0])&nbsp;<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">return<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;i;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u5b50\u4e32\u7ed3\u675f\uff0c\u8bf4\u660e\u5339\u914d\u6210\u529f<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">else<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">return<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;0;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">}<span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/Index<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<\/ol>\n<\/div>\n<p>&nbsp; \u4e0d\u8fc7\uff0c\u4e5f\u6709\u7279\u6b8a\u60c5\u51b5\u53ef\u4ee5\u4e0d\u56de\u6eaf\uff0c\u5982\u4e0b\uff1a<br \/>\n<span style=\"white-space:pre\"><\/span>abcdefghij(<span style=\"font-family:\u5b8b\u4f53\">\u4e3b\u4e32<\/span>)<br \/>\n<span style=\"white-space:pre\"><\/span>abcdefg(<span style=\"font-family:\u5b8b\u4f53\">\u6a21\u5f0f\u4e32<\/span>)<br \/>\n&nbsp; \u5373(<span style=\"font-family:\u5b8b\u4f53\">\u6a21\u5f0f\u4e32<\/span>)<span style=\"font-family:\u5b8b\u4f53\">\u6ca1\u6709\u76f8\u540c\u7684\u624d\u4e0d\u9700\u8981\u56de\u6eaf\u3002<\/span><\/p>\n<p>\n<strong>4<span style=\"font-family:\u5b8b\u4f53\">\u3001<\/span>KMP&nbsp;<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u601d\u60f3<\/span><\/strong><br \/>\n&nbsp;&nbsp;&nbsp; \u666e\u901a\u7684\u5b57\u7b26\u4e32\u5339\u914d\u7b97\u6cd5\u5fc5\u987b\u8981\u56de\u6eaf\u3002\u4f46\u56de\u6eaf\u5c31\u5f71\u54cd\u4e86\u6548\u7387\uff0c\u56de\u6eaf\u662f\u7531T\u4e32\u672c\u8eab\u7684\u6027\u8d28\u51b3\u5b9a\u7684\uff0c\u662f\u56e0\u4e3aT\u4e32\u672c\u8eab\u6709\u524d\u540e'\u90e8\u5206\u5339\u914d'\u7684\u6027\u8d28\u3002\u50cf\u4e0a\u9762\u6240\u8bf4\u5982\u679c\u4e3b\u4e32\u4e3aabcdef\u8fd9\u6837\u7684\uff0c\u5927\u6ca1\u6709\u56de\u6eaf\u7684\u5fc5\u8981\u3002<\/p>\n<p>&nbsp;&nbsp;&nbsp; \u6539\u8fdb\u7684\u5730\u65b9\u4e5f\u5c31\u662f\u8fd9\u91cc\uff0c\u6211\u4eec\u4eceT<span style=\"font-family:\u5b8b\u4f53\">\u4e32\u672c\u8eab\u51fa\u53d1\uff0c\u4e8b\u5148\u5c31\u627e\u51c6\u4e86<\/span>T<span style=\"font-family:\u5b8b\u4f53\">\u81ea\u8eab\u524d\u540e\u90e8\u5206\u5339\u914d\u7684\u4f4d\u7f6e\uff0c\u90a3\u5c31\u53ef\u4ee5\u6539\u8fdb\u7b97\u6cd5\u3002<\/span><\/p>\n<p>&nbsp;&nbsp;&nbsp; \u5982\u679c\u4e0d\u7528\u56de\u6eaf\uff0c\u90a3\u6a21\u5f0f\u4e32\u4e0b\u4e00\u4e2a\u4f4d\u7f6e\u4ece\u54ea\u91cc\u5f00\u59cb\u5462\uff1f<\/p>\n<p>&nbsp;&nbsp;&nbsp; \u8fd8\u662f\u4e0a\u9762\u90a3\u4e2a\u4f8b\u5b50\uff0cT(<span style=\"font-family:\u5b8b\u4f53\">\u6a21\u5f0f\u4e32<\/span>)<span style=\"font-family:\u5b8b\u4f53\">\u4e3a<\/span>ababc<span style=\"font-family:\u5b8b\u4f53\">\uff0c\u5982\u679c<\/span>c<span style=\"font-family:\u5b8b\u4f53\">\u5931\u914d\uff0c\u90a3\u5c31\u53ef\u4ee5\u5f80\u524d\u79fb\u5230<\/span>aba<span style=\"font-family:\u5b8b\u4f53\">\u6700\u540e\u4e00\u4e2a<\/span>a<span style=\"font-family:\u5b8b\u4f53\">\u7684\u4f4d\u7f6e\uff0c\u50cf\u8fd9\u6837\uff1a<\/span><\/p>\n<\/div>\n<blockquote style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left; margin:0px 0px 0px 40px; padding:0px\">\n<div class=\"Section0\">\n<p>...ababd...<\/p>\n<\/div>\n<div class=\"Section0\">\n<p>&nbsp;&nbsp; ababc<\/p>\n<\/div>\n<div class=\"Section0\">\n<p>&nbsp;&nbsp;&nbsp; -&gt;ababc<\/p>\n<\/div>\n<\/blockquote>\n<div class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<p>\u8fd9\u6837i<span style=\"font-family:\u5b8b\u4f53\">\u4e0d\u7528\u56de\u6eaf\uff0c<\/span>j<span style=\"font-family:\u5b8b\u4f53\">\u8df3\u5230\u524d<\/span>2<span style=\"font-family:\u5b8b\u4f53\">\u4e2a\u4f4d\u7f6e\uff0c\u7ee7\u7eed\u5339\u914d\u7684\u8fc7\u7a0b\uff0c\u8fd9\u5c31\u662f<\/span>KMP<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u6240\u5728\u3002\u8fd9\u4e2a\u5f53<\/span>T[j]<span style=\"font-family:\u5b8b\u4f53\">\u5931\u914d\u540e\uff0c<\/span><strong>j&nbsp;<span style=\"font-family:\u5b8b\u4f53\">\u5e94\u8be5\u5f80\u524d\u8df3\u7684&#20540;\u5c31\u662f<\/span>j<span style=\"font-family:\u5b8b\u4f53\">\u7684<\/span>next<span style=\"font-family:\u5b8b\u4f53\">&#20540;<\/span>\uff0c\u5b83\u662f\u7531T<span style=\"font-family:\u5b8b\u4f53\">\u4e32\u672c\u8eab\u56fa\u6709\u51b3\u5b9a\u7684\uff0c\u4e0e<\/span>S<span style=\"font-family:\u5b8b\u4f53\">\u4e32<\/span>(<span style=\"font-family:\u5b8b\u4f53\">\u4e3b\u4e32<\/span>)<span style=\"font-family:\u5b8b\u4f53\">\u65e0\u5173<\/span><\/strong>\u3002<\/p>\n<p>\n<strong>5\u3001next<span style=\"font-family:\u5b8b\u4f53\">\u6570\u7ec4\u7684\u542b\u4e49<\/span><\/strong><\/p>\n<p>\u91cd\u70b9\u6765\u4e86\u3002\u4e0b\u9762\u89e3\u91ca\u4e00\u4e0bnext<span style=\"font-family:\u5b8b\u4f53\">\u6570\u7ec4\u7684\u542b\u4e49<\/span>\uff0c\u8fd9\u4e2a\u4e5f\u662fKMP<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u4e2d\u6bd4\u8f83\u4e0d\u597d\u7406\u89e3\u7684\u4e00\u70b9\u3002<\/span><\/p>\n<p>&nbsp; \u4ee4\u539f\u59cb\u4e32\u4e3a: S[i]<span style=\"font-family:\u5b8b\u4f53\">\uff0c\u5176\u4e2d<\/span>0&lt;=i&lt;=n<span style=\"font-family:\u5b8b\u4f53\">\uff1b\u6a21\u5f0f\u4e32\u4e3a<\/span>: T[j]<span style=\"font-family:\u5b8b\u4f53\">\uff0c\u5176\u4e2d<\/span>0&lt;=j&lt;=m<span style=\"font-family:\u5b8b\u4f53\">\u3002<\/span><\/p>\n<p>&nbsp; \u5047\u8bbe\u76ee\u524d\u5339\u914d\u5230\u5982\u4e0b\u4f4d\u7f6e<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; S0,S1,S2,...,<span style=\"color:rgb(51,204,0)\">Si-j,Si-j&#43;1...............,Si-1<\/span>,&nbsp;<span style=\"color:rgb(204,0,0)\">Si<\/span>, Si&#43;1,....,Sn<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color:rgb(51,204,0)\">T0,T1,.....................,Tj-1<\/span>,&nbsp;<span style=\"color:rgb(204,0,0)\">Tj<\/span>, ..........<\/p>\n<p>&nbsp; S<span style=\"font-family:\u5b8b\u4f53\">\u548c<\/span>T<span style=\"font-family:\u5b8b\u4f53\">\u7684\u7eff\u8272\u90e8\u5206\u5339\u914d\u6210\u529f\uff0c\u6070\u597d\u5230<\/span>Si<span style=\"font-family:\u5b8b\u4f53\">\u548c<\/span>Tj<span style=\"font-family:\u5b8b\u4f53\">\u7684\u65f6\u5019\u5931\u914d\uff0c\u5982\u679c\u8981\u4fdd\u6301<\/span>i<span style=\"font-family:\u5b8b\u4f53\">\u4e0d\u53d8\uff0c\u540c\u65f6\u8fbe\u5230\u8ba9\u6a21\u5f0f\u4e32<\/span>T<span style=\"font-family:\u5b8b\u4f53\">\u76f8\u5bf9\u4e8e\u539f\u59cb\u4e32<\/span>S<span style=\"font-family:\u5b8b\u4f53\">\u53f3\u79fb\u7684\u8bdd\uff0c\u53ef\u4ee5\u66f4\u65b0<\/span>j<span style=\"font-family:\u5b8b\u4f53\">\u7684&#20540;\uff0c\u8ba9<\/span>Si<span style=\"font-family:\u5b8b\u4f53\">\u548c\u65b0\u7684<\/span>Tj<span style=\"font-family:\u5b8b\u4f53\">\u8fdb\u884c\u5339\u914d\uff0c\u5047\u8bbe\u65b0\u7684<\/span>j<span style=\"font-family:\u5b8b\u4f53\">\u7528<\/span>next[j]<span style=\"font-family:\u5b8b\u4f53\">\u8868\u793a\uff0c\u5373\u8ba9<\/span>Si<span style=\"font-family:\u5b8b\u4f53\">\u548c<\/span>next[j]<span style=\"font-family:\u5b8b\u4f53\">\u5339\u914d\uff0c\u663e\u7136\u65b0\u7684<\/span>j<span style=\"font-family:\u5b8b\u4f53\">&#20540;\u8981\u5c0f\u4e8e\u4e4b\u524d\u7684<\/span>j<span style=\"font-family:\u5b8b\u4f53\">&#20540;\uff0c\u6a21\u5f0f\u4e32\u624d\u4f1a\u662f\u53f3\u79fb\u7684\u6548\u679c\uff0c\u4e5f\u5c31\u662f\u8bf4\u5e94\u8be5\u6709<\/span>next[j]<br \/>\n &lt;= j -1<span style=\"font-family:\u5b8b\u4f53\">\u3002\u90a3\u65b0\u7684<\/span>j<span style=\"font-family:\u5b8b\u4f53\">&#20540;\u4e5f\u5c31\u662f<\/span>next[j]<span style=\"font-family:\u5b8b\u4f53\">\u5e94\u8be5\u662f\u591a\u5c11\u5462\uff1f\u6211\u4eec\u89c2\u5bdf\u5982\u4e0b\u7684\u5339\u914d\uff1a<\/span><\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1)<span style=\"font-family:\u5b8b\u4f53\">\u5982\u679c<\/span>\u6a21\u5f0f\u4e32\u53f3\u79fb1<span style=\"font-family:\u5b8b\u4f53\">\u4f4d\uff08\u4ece\u7b80\u5355\u7684\u601d\u8003\u8d77\uff0c\u79fb\u52a8\u4e00\u4f4d\u4f1a\u600e\u4e48\u6837\uff09<\/span>\uff0c\u5373next[j] = j - 1<span style=\"font-family:\u5b8b\u4f53\">\uff0c \u5373\u8ba9\u84dd\u8272\u7684<\/span>Si<span style=\"font-family:\u5b8b\u4f53\">\u548c<\/span>Tj-1<span style=\"font-family:\u5b8b\u4f53\">\u5339\u914d<\/span>(<span style=\"font-family:\u5b8b\u4f53\">\u6ce8\uff1a\u7701\u7565\u53f7\u4e3a\u672a\u5339\u914d\u90e8\u5206<\/span>)<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; S0,S1,S2,...,<span style=\"color:rgb(51,204,0)\">Si-j,Si-j&#43;1...............,Si-1<\/span>,&nbsp;<span style=\"color:rgb(51,102,255)\">Si<\/span>, Si&#43;1,....,Sn<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color:rgb(51,204,0)\">T0,T1,.....................,Tj-1<\/span>,&nbsp;<span style=\"color:rgb(204,0,0)\">Tj<\/span>, .......... (T\u7684\u5212\u7ebf\u90e8\u5206\u548cS\u5212\u7ebf\u90e8\u5206\u76f8\u7b49\u30101\u3011)<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color:rgb(51,204,0)\">T0,T1,.................Tj-2<\/span>,<span style=\"color:rgb(51,102,255)\">Tj-1<\/span>,&nbsp;....... (\u79fb\u52a8\u540e\u7684T\u7684\u5212\u7ebf\u90e8\u5206\u548cS\u7684\u5212\u7ebf\u90e8\u5206\u76f8\u7b49\u30102\u3011)<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u6839\u636e\u30101<span style=\"font-family:\u5b8b\u4f53\">\u3011\u3010<\/span>2<span style=\"font-family:\u5b8b\u4f53\">\u3011\u53ef\u4ee5\u77e5\u9053\u5f53<\/span>next[j] =j -1<span style=\"font-family:\u5b8b\u4f53\">\uff0c\u5373\u6a21\u5f0f\u4e32\u53f3\u79fb\u4e00\u4f4d\u7684\u65f6\u5019\uff0c\u6709<\/span>T[0 ~ j-2] == T[1 ~ j-1]\uff0c<span style=\"font-family:\u5b8b\u4f53\">\u800c\u8fd9\u4e24\u90e8\u5206\u6070\u597d\u662f\u5b57\u7b26\u4e32<\/span>T[0 ~j-1]<span style=\"font-family:\u5b8b\u4f53\">\u7684\u524d\u7f00\u548c\u540e\u7f00<\/span><span style=\"font-family:\u5b8b\u4f53\">\uff0c\u4e5f\u5c31\u662f\u8bf4<\/span>next[j]<span style=\"font-family:\u5b8b\u4f53\">\u7684&#20540;\u53d6\u51b3\u4e8e\u6a21\u5f0f\u4e32<\/span>T<span style=\"font-family:\u5b8b\u4f53\">\u4e2d<\/span>j<span style=\"font-family:\u5b8b\u4f53\">\u524d\u9762\u90e8\u5206\u7684\u524d\u7f00\u548c\u540e\u7f00\u76f8\u7b49\u90e8\u5206\u7684\u957f\u5ea6\uff08\u597d\u597d\u63e3\u6469\u8fd9\u4e24\u4e2a\u5173\u952e\u5b57\u6982\u5ff5\uff1a\u524d\u7f00\u3001\u540e\u7f00\uff0c\u6216\u8005\u518d\u60f3\u60f3\uff0c\u6211\u7684\u4e0a\u4e00\u7bc7\u6587\u7ae0\uff0c\u4ece<\/span>Trie<span style=\"font-family:\u5b8b\u4f53\">\u6811\u8c08\u5230\u540e\u7f00\u6811\u4e2d\uff0c\u540e\u7f00\u6811\u7684\u6982\u5ff5\uff09\u3002<\/span><\/p>\n<\/div>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2)<span style=\"font-family:\u5b8b\u4f53\">\u5982\u679c\u6a21\u5f0f\u4e32\u53f3\u79fb<\/span>2<span style=\"font-family:\u5b8b\u4f53\">\u4f4d\uff0c\u5373<\/span>next[j] = j - 2<span style=\"font-family:\u5b8b\u4f53\">\uff0c \u5373\u8ba9\u84dd\u8272\u7684<\/span>Si<span style=\"font-family:\u5b8b\u4f53\">\u548c<\/span>Tj-2<span style=\"font-family:\u5b8b\u4f53\">\u5339\u914d&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; S0,S1,...,<span style=\"color:rgb(51,204,0)\">Si-j,Si-j&#43;1,Si-j&#43;2...............,Si-1<\/span>,&nbsp;<span style=\"color:rgb(51,102,255)\">Si<\/span>, Si&#43;1,....,Sn<\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color:rgb(51,204,0)\">T0,T1,T2,.....................,Tj-1<\/span>,&nbsp;<span style=\"color:rgb(204,0,0)\">Tj<\/span>, ..........(T\u7684\u5212\u7ebf\u90e8\u5206\u548cS\u5212\u7ebf\u90e8\u5206\u76f8\u7b49\u30103\u3011)<\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color:rgb(51,204,0)\">T0,T1,...............,Tj-3<\/span>,<span style=\"color:rgb(51,102,255)\">Tj-2<\/span>,.........(\u79fb\u52a8\u540e\u7684T\u7684\u5212\u7ebf\u90e8\u5206\u548cS\u7684\u5212\u7ebf\u90e8\u5206\u76f8\u7b49\u30104\u3011)<\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u540c\u6837\u6839\u636e\u30103<span style=\"font-family:\u5b8b\u4f53\">\u3011\u3010<\/span>4<span style=\"font-family:\u5b8b\u4f53\">\u3011\u53ef\u4ee5\u77e5\u9053\u5f53<\/span>next[j] =j -2<span style=\"font-family:\u5b8b\u4f53\">\uff0c\u5373\u6a21\u5f0f\u4e32\u53f3\u79fb\u4e24\u4f4d\u7684\u65f6\u5019\uff0c\u6709<\/span>T[0 ~ j-3] == T[2 ~ j-1]<span style=\"font-family:\u5b8b\u4f53\">\u3002\u800c\u8fd9\u4e24\u90e8\u5206\u4e5f\u6070\u597d\u662f\u5b57\u7b26\u4e32<\/span>T[0 ~j-1]<span style=\"font-family:\u5b8b\u4f53\">\u7684\u524d\u7f00\u548c\u540e\u7f00\uff0c\u4e5f\u5c31\u662f\u8bf4<\/span>next[j]<span style=\"font-family:\u5b8b\u4f53\">\u7684&#20540;\u53d6\u51b3\u4e8e\u6a21\u5f0f\u4e32<\/span>T<span style=\"font-family:\u5b8b\u4f53\">\u4e2d<\/span>j<span style=\"font-family:\u5b8b\u4f53\">\u524d\u9762\u90e8\u5206\u7684\u524d\u7f00\u548c\u540e\u7f00\u76f8\u7b49\u90e8\u5206\u7684\u957f\u5ea6<\/span>\u3002<\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp;&nbsp; 3)<span style=\"font-family:\u5b8b\u4f53\">\u4f9d\u6b21\u7c7b\u63a8\uff0c\u53ef\u4ee5\u5f97\u5230\u5982\u4e0b\u7ed3\u8bba\uff1a<\/span><strong>\u5f53\u53d1\u751f\u5931\u914d\u7684\u60c5\u51b5\u4e0b\uff0cj<span style=\"font-family:\u5b8b\u4f53\">\u7684\u65b0&#20540;<\/span>next[j]<span style=\"font-family:\u5b8b\u4f53\">\u53d6\u51b3\u4e8e\u6a21\u5f0f\u4e32\u4e2d<\/span>T[0 ~ j-1]<span style=\"font-family:\u5b8b\u4f53\">\u4e2d\u524d\u7f00\u548c\u540e\u7f00\u76f8\u7b49\u90e8\u5206\u7684\u957f\u5ea6\uff0c \u5e76\u4e14<\/span>next[j]<span style=\"font-family:\u5b8b\u4f53\">\u6070\u597d\u7b49\u4e8e\u8fd9\u4e2a\u6700\u5927\u957f\u5ea6<\/span><\/strong>\u3002<\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; \u4e3a\u6b64\uff0c\u8bf7\u518d\u5141\u8bb8\u6211\u5f15\u7528\u4e0a\u6587\u4e2d\u7684\u4e00\u6bb5\u539f\u6587\uff1a<span style=\"font-size:24px\">\u201c<\/span>KMP<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u4e2d\uff0c\u5982\u679c\u5f53\u524d\u5b57\u7b26\u5339\u914d\u6210\u529f\uff0c\u5373<\/span>S[i]==T[j]<span style=\"font-family:\u5b8b\u4f53\">\uff0c\u4ee4<\/span>i&#43;&#43;<span style=\"font-family:\u5b8b\u4f53\">\uff0c<\/span>j&#43;&#43;<span style=\"font-family:\u5b8b\u4f53\">\uff0c\u7ee7\u7eed\u5339\u914d\u4e0b\u4e00\u4e2a\u5b57\u7b26\uff1b\u5982\u679c<\/span>\u5339\u914d\u5931\u8d25\uff0c\u5373S[i]<br \/>\n != T[j]<span style=\"font-family:\u5b8b\u4f53\">\uff0c\u9700\u8981\u4fdd\u6301<\/span>i<span style=\"font-family:\u5b8b\u4f53\">\u4e0d\u53d8\uff0c\u5e76\u4e14\u8ba9<\/span>j = next[j]<span style=\"font-family:\u5b8b\u4f53\">\uff0c\u8fd9\u91cc<\/span>next[j] &lt;=j -1<span style=\"font-family:\u5b8b\u4f53\">\uff0c\u5373\u6a21\u5f0f\u4e32<\/span>T<span style=\"font-family:\u5b8b\u4f53\">\u76f8\u5bf9\u4e8e\u539f\u59cb\u4e32<\/span>S<span style=\"font-family:\u5b8b\u4f53\">\u5411\u53f3\u79fb\u52a8\u4e86\u81f3\u5c11<\/span>1<span style=\"font-family:\u5b8b\u4f53\">\u4f4d<\/span>(<span style=\"font-family:\u5b8b\u4f53\"><strong>\u79fb\u52a8\u7684\u5b9e\u9645\u4f4d\u6570<\/strong><\/span><strong>j<br \/>\n - next[j]&nbsp; &gt;=1<\/strong>),<\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; \u540c\u65f6\u79fb\u52a8\u4e4b\u540e\uff0c<u>i<span style=\"font-family:\u5b8b\u4f53\">\u4e4b\u524d\u7684\u90e8\u5206\uff08\u5373<\/span>S[i-j&#43;1 ~ i-1]<span style=\"font-family:\u5b8b\u4f53\">\uff09\uff0c\u548c<\/span>j=next[j]<span style=\"font-family:\u5b8b\u4f53\">\u4e4b\u524d\u7684\u90e8\u5206\uff08\u5373<\/span>T[0 ~ j-2]<\/u><span style=\"font-family:\u5b8b\u4f53\"><u>\uff09\u4ecd\u7136\u76f8\u7b49<\/u>\u3002\u663e\u7136\uff0c<strong>\u76f8\u5bf9\u4e8e<\/strong><\/span><strong>BF<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u6765\u8bf4\uff0c<\/span>KMP<\/strong><span style=\"font-family:\u5b8b\u4f53\"><strong>\u79fb\u52a8\u66f4\u591a\u7684\u4f4d\u6570\uff0c\u8d77\u5230\u4e86\u4e00\u4e2a\u52a0\u901f\u7684\u4f5c\u7528<\/strong>\uff01&nbsp;<\/span>(<span style=\"font-family:\u5b8b\u4f53\">\u5931\u914d\u7684\u7279\u6b8a\u60c5\u5f62\uff0c\u4ee4<\/span>j=next[j]<span style=\"font-family:\u5b8b\u4f53\">\u5bfc\u81f4<\/span>j==0<span style=\"font-family:\u5b8b\u4f53\">\u7684\u65f6\u5019\uff0c\u9700\u8981\u5c06<\/span>i<br \/>\n &#43;&#43;\uff0c\u5426\u5219\u6b64\u65f6\u6ca1\u6709\u79fb\u52a8\u6a21\u5f0f\u4e32)<span style=\"font-family:\u5b8b\u4f53\">\u3002\u201d<\/span><\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; \u4e8e\u6b64\uff0c\u4e5f\u5c31\u4e0d\u96be\u7406\u89e3\u4e86\u6211\u7684\u5173\u4e8eKMP\u7b97\u6cd5\u7684\u7b2c\u4e8c\u7bc7\u6587\u7ae0\u4e4b\u4e2d\uff1a<span style=\"font-size:24px\">\u201c<\/span>\u5f53\u5339\u914d\u5230S[i] != P[j]\u7684\u65f6\u5019\u6709 S[i-j\u2026i-1] = P[0\u2026j-1]. \u5982\u679c\u4e0b\u9762\u7528j_next\u53bb\u5339\u914d\uff0c\u5219\u6709P[0\u2026j_next-1] = S[i-j_next\u2026i-1] = P[j-j_next\u2026j-1]\u3002\u6b64\u8fc7\u7a0b\u5982\u4e0b\u56fe3-1\u6240\u793a\u3002<\/p>\n<p class=\"p0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left; padding-left:60px; margin-top:0pt; margin-bottom:0pt; vertical-align:baseline\">\n<span style=\"font-size:13px\"><span style=\"font-family:\u5b8b\u4f53\">&nbsp; \u5f53\u5339\u914d\u5230<\/span><span style=\"font-family:Calibri\">S[i] != P[j]<\/span><span style=\"font-family:\u5b8b\u4f53\">\u65f6\uff0c<span style=\"font-family:Verdana\">S[i-j\u2026i-1] = P[0\u2026j-1]<\/span>\uff1a<\/span><\/span><\/p>\n<p class=\"p0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left; padding-left:90px; margin-top:0pt; margin-bottom:0pt; vertical-align:baseline\">\n<span style=\"font-size:13px\"><span style=\"font-family:Calibri\">S: 0 \u2026&nbsp;<\/span><u>i-j \u2026 i-1<\/u><span style=\"font-family:Calibri\">&nbsp;i \u2026<\/span><\/span><\/p>\n<p class=\"p0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left; padding-left:90px; margin-top:0pt; margin-bottom:0pt; vertical-align:baseline\">\n<span style=\"font-size:13px\"><span style=\"font-family:Calibri\">P:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><u>0 \u2026&nbsp;&nbsp; j-1<\/u><span style=\"font-family:Calibri\">&nbsp;j \u2026<\/span><\/span><\/p>\n<p class=\"p0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left; padding-left:60px; margin-top:0pt; margin-bottom:0pt; vertical-align:baseline\">\n<span style=\"font-size:13px\"><span style=\"font-family:\u5b8b\u4f53\"><span style=\"font-family:Verdana\"><span style=\"font-family:\u5b8b\u4f53\">&nbsp; \u5982\u679c\u4e0b\u9762\u7528j_next\u53bb\u5339\u914d\uff0c\u5219\u6709P[0\u2026j_next-1] = S[i-j_next\u2026i-1] = P[j-j_next\u2026j-1]\u3002<br \/>\n\u6240\u4ee5\u5728P\u4e2d\u6709\u5982\u4e0b\u5339\u914d\u5173\u7cfb\uff08\u83b7\u5f97\u8fd9\u4e2a\u5339\u914d\u5173\u7cfb\u7684\u610f\u4e49\u662f\u7528\u6765\u6c42next\u6570\u7ec4\uff09<\/span><\/span><\/span><span style=\"font-family:\u5b8b\u4f53\">\uff1a<\/span><\/span><\/p>\n<p class=\"p0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left; padding-left:90px; margin-top:0pt; margin-bottom:0pt; vertical-align:baseline\">\n<span style=\"font-size:13px\"><span style=\"font-family:Calibri\">P: 0 \u2026&nbsp;<\/span><u>j-j_next&nbsp; .\u2026j-1_<\/u><span style=\"font-family:Calibri\">&nbsp;&nbsp;&nbsp; \u2026<\/span><\/span><\/p>\n<p class=\"p0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left; padding-left:90px; margin-top:0pt; margin-bottom:0pt; vertical-align:baseline\">\n<span style=\"font-size:13px\"><span style=\"font-family:Calibri\">P:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><u>0&nbsp;&nbsp;&nbsp; \u2026 .j_next-1<\/u><span style=\"font-family:Calibri\">&nbsp;\u2026<\/span><\/span><\/p>\n<p class=\"p0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left; padding-left:60px; margin-top:0pt; margin-bottom:0pt; vertical-align:baseline\">\n<span style=\"font-size:13px\"><span style=\"font-family:\u5b8b\u4f53\">&nbsp; \u6240\u4ee5\uff0c<\/span><span style=\"font-family:\u5b8b\u4f53\">\u6839\u636e\u4e0a\u9762\u4e24\u4e2a\u6b65\u9aa4\uff0c\u63a8\u51fa<\/span><span style=\"font-family:\u5b8b\u4f53\">\u4e0b\u4e00\u5339\u914d\u4f4d\u7f6e<\/span><span style=\"font-family:Calibri\">j_next:<\/span><\/span><\/p>\n<p class=\"p0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left; padding-left:90px; margin-top:0pt; margin-bottom:0pt; vertical-align:baseline\">\n<span style=\"font-size:13px\"><span style=\"font-family:Calibri\">S: 0 \u2026 i-j \u2026&nbsp;<\/span><u>i-j_next \u2026&nbsp;&nbsp; i-1&nbsp;&nbsp;<\/u><span style=\"font-family:Calibri\">&nbsp;&nbsp;<\/span><span style=\"font-family:\u5b8b\u4f53\">&nbsp;&nbsp;<\/span><span style=\"font-family:Calibri\">i \u2026<\/span><\/span><\/p>\n<p class=\"p0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left; padding-left:90px; margin-top:0pt; margin-bottom:0pt\">\n<span style=\"font-size:13px\"><span style=\"font-family:Calibri\">P:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><u>0&nbsp;&nbsp; \u2026&nbsp;<strong>j_next-1<\/strong><\/u><span style=\"font-family:Calibri\">&nbsp;<\/span><span style=\"font-family:\u5b8b\u4f53\"><\/span><span style=\"font-family:Calibri\">j_next \u2026<\/span><\/span><\/p>\n<p class=\"p0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left; padding-left:60px; margin-top:0pt; margin-bottom:0pt\">\n<span style=\"font-family:Calibri; font-size:12pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u56fe3-1 \u6c42j-next\uff08\u6700\u5927\u7684&#20540;\uff09\u7684\u4e09\u4e2a\u6b65\u9aa4<\/span><\/p>\n<p class=\"p0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left; margin-top:0pt; margin-bottom:0pt\">\n&nbsp;&nbsp;&nbsp; \u4e0b\u9762\uff0c<strong>\u6211\u4eec\u7528\u53d8\u91cfk\u6765\u4ee3\u8868\u6c42\u5f97\u7684j_next\u7684\u6700\u5927&#20540;<\/strong>\uff0c\u5373k\u8868\u793a\u8fd9S[i]\u3001P[j]\u4e0d\u5339\u914d\u65f6P\u4e2d\u4e0b\u4e00\u4e2a\u7528\u6765\u5339\u914d\u7684\u4f4d\u7f6e\uff0c\u4f7f\u5f97<u>P[0\u2026k-1] = P[j-k\u2026j-1]<\/u>\uff0c\u800c\u6211\u4eec\u8981\u5c3d\u91cf\u627e\u5230\u8fd9\u4e2ak\u7684\u6700\u5927&#20540;\u3002<span style=\"font-family:Arial,Verdana,sans-serif; color:rgb(0,0,0); line-height:normal\"><span style=\"font-size:24px\">\u201d\u3002<\/span><\/span><\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u6839\u636e\u4e0a\u6587\u7684\u30101\u3011\u4e0e\u30102\u3011\u7684\u5339\u914d\u60c5\u51b5\uff0c\u53ef\u5f97\u7b2c\u4e8c\u7bc7\u6587\u7ae0\u4e4b\u4e2d\u6240\u8c13\u7684k=1\uff08\u5982aaaa\u7684\u5f62\u5f0f\uff09\uff0c\u6839\u636e\u4e0a\u6587\u7684\u30103\u3011\u4e0e\u30104\u3011\u7684\u5339\u914d\u60c5\u51b5\uff0ck=2\uff08\u5982abab\u7684\u5f62\u5f0f\uff09\u3002<\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp;&nbsp; \u6240\u4ee5\uff0c\u5f52\u6839\u7a76\u5e95\uff0c<span style=\"color:rgb(204,0,0)\">KMP\u7b97\u6cd5\u7684\u672c\u8d28<\/span>\u4fbf\u662f\uff1a\u9488\u5bf9\u5f85\u5339\u914d\u7684\u6a21\u5f0f\u4e32\u7684\u7279\u70b9\uff0c\u5224\u65ad\u5b83\u662f\u5426\u6709\u91cd\u590d\u7684\u5b57\u7b26\uff0c\u4ece\u800c\u627e\u5230\u5b83\u7684\u524d\u7f00\u4e0e\u540e\u7f00\uff0c\u8fdb\u800c\u6c42\u51fa\u76f8\u5e94\u7684Next\u6570\u7ec4\uff0c\u6700\u7ec8\u6839\u636eNext\u6570\u7ec4\u800c\u8fdb\u884cKMP\u5339\u914d\u3002\u63a5\u4e0b\u6765\uff0c\u8fdb\u5165\u672c\u6587\u7684\u7b2c\u4e8c\u90e8\u5206\u3002<\/p>\n<h3 class=\"Section0\" style=\"margin:0px; padding:0px; color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left\">\n<a name=\"t2\" style=\"color:rgb(51,102,153)\"><\/a>\u7b2c\u4e8c\u90e8\u5206\u3001next<span style=\"font-family:\u5b8b\u4f53\">\u6570\u7ec4\u6c42\u6cd5\u7684\u6765\u9f99\u53bb\u8109\u4e0e<\/span>KMP<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u7684\u6e90\u7801<\/span><\/h3>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; \u672c\u90e8\u5206\u5f15\u81ea\u4e2a\u4eba\u6b64\u524d\u7684\u5173\u4e8eKMP<span style=\"font-family:\u5b8b\u4f53\">\u7b97\u6cd5\u7684\u7b2c\u4e8c\u7bc7\u6587\u7ae0\uff1a\u516d\u4e4b\u7eed\u3001\u7531KMP\u7b97\u6cd5\u8c08\u5230BM\u7b97\u6cd5\u3002\u524d\u9762\uff0c\u6211\u4eec\u5df2\u7ecf\u77e5\u9053<span style=\"font-family:Arial\">\u5373\u4e0d\u80fd\u8ba9P[j]=P[next[j]]\u6210\u7acb\u6210\u7acb\u3002\u4e0d\u80fd\u518d\u51fa\u73b0\u4e0a\u9762\u90a3\u6837\u7684\u60c5\u51b5\u554a\uff01<\/span><span style=\"font-family:Arial\">\u5373\u4e0d\u80fd\u6709\u8fd9\u79cd\u60c5\u51b5\u51fa\u73b0\uff1aP[3]=b\uff0c\u800c\u7adf\u4e5f\u6709P[next[3]]=P[1]=b<\/span><span style=\"font-family:Arial\">\u3002<\/span><\/span><\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<span style=\"font-family:\u5b8b\u4f53\"><span style=\"font-family:Arial\">&nbsp;&nbsp;&nbsp; \u6b63\u5982\u5728\u7b2c\u4e8c\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6240\u63d0\u5230\u7684\u90a3\u6837\uff1a\u201c\u8fd9\u91cc\u8bfb\u8005\u7406\u89e3\u53ef\u80fd\u6709\u56f0\u96be\u7684\u662f\u56e0\u4e3a\u6587\u4e2d\uff0c\u65f6\u800cnext\uff0c\u65f6\u800cnextval\uff0c\u628a\u4ed6\u4eec\u7684\u601d\u7ef4\u641e\u6df7\u4e71\u4e86\u3002\u5176\u5b9enext\u7528\u4e8e\u8868\u8fbe\u6570\u7ec4\u7d22\u5f15\uff0c\u800cnextval\u4e13\u7528\u4e8e\u8868\u8fbenext\u6570\u7ec4\u7d22\u5f15\u4e0b\u7684\u5177\u4f53\u5404&#20540;\uff0c\u533a\u522b\u7ec6\u5fae\u3002\u81f3\u4e8e\u6587\u4e2d\u8bf4\u4e0d\u5141\u8bb8P<img decoding=\"async\" title=\"[j]\" alt=\"[j]\" src=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/other_site\/img_t_newj_org.gif\" type=\"face\" style=\"border:none\" \/>=P[next[j]<br \/>\n ]\u51fa\u73b0\uff0c\u662f\u56e0\u4e3a\u5df2\u7ecf\u6709P<img decoding=\"async\" title=\"[3]\" alt=\"[3]\" src=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/other_site\/img_t_three_org.gif\" type=\"face\" style=\"border:none\" \/>=b\u4e0eS<img decoding=\"async\" title=\"[i]\" alt=\"[i]\" src=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/other_site\/img_t_weiboi_org.gif\" type=\"face\" style=\"border:none\" \/>\u5339\u914d\u8d25\uff0c\u800cP[next<img decoding=\"async\" title=\"[3]\" alt=\"[3]\" src=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/other_site\/img_t_three_org.gif\" type=\"face\" style=\"border:none\" \/>]=P1=b\uff0c\u82e5\u518d\u62ffP[1]=b\u53bb\u4e0eS<img decoding=\"async\" title=\"[i]\" alt=\"[i]\" src=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/other_site\/img_t_weiboi_org.gif\" type=\"face\" style=\"border:none\" \/>\u5339\u914d\u5219\u5fc5\u8d25\u3002\u201d--<span style=\"font-family:\u5b8b\u4f53\">\u516d\u4e4b\u7eed\u3001\u7531KMP\u7b97\u6cd5\u8c08\u5230BM\u7b97\u6cd5\u3002<\/span><\/span><\/span><\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<span style=\"font-family:\u5b8b\u4f53\"><span style=\"font-family:Arial\"><span style=\"font-family:\u5b8b\u4f53\">&nbsp;&nbsp; \u53c8\u6070\u6070\u5982\u4e0a\u6587\u4e2d\u6240\u8ff0\uff1a\u201c\u6a21\u5f0f\u4e32<span style=\"font-family:Arial\">T<\/span>\u76f8\u5bf9\u4e8e\u539f\u59cb\u4e32<span style=\"font-family:Arial\">S<\/span>\u5411\u53f3\u79fb\u52a8\u4e86\u81f3\u5c11<span style=\"font-family:Arial\">1<\/span>\u4f4d<span style=\"font-family:Arial\">(<\/span><strong>\u79fb\u52a8\u7684\u5b9e\u9645\u4f4d\u6570<\/strong><span style=\"font-family:Arial\">j<br \/>\n - next[j]&nbsp; &gt;=1<\/span><span style=\"font-family:Arial\">)<\/span><span style=\"font-family:Arial\"><span style=\"font-size:24px\">\u201d<\/span><\/span><span style=\"font-family:Arial\">\u3002<\/span><\/span><\/span><\/span><\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<span style=\"font-family:\u5b8b\u4f53\">&nbsp;&nbsp;&nbsp; ok\uff0c\u6c42<\/span>next<span style=\"font-family:\u5b8b\u4f53\">\u6570\u7ec4\u7684<\/span>get_nextval<span style=\"font-family:\u5b8b\u4f53\">\u51fd\u6570\u6b63\u786e\u4ee3\u7801\u5982\u4e0b\uff1a<\/span><\/p>\n<div class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<div class=\"dp-highlighter bg_cpp\" style=\"font-family:Consolas,'Courier New',Courier,mono,serif; font-size:12px; background-color:rgb(231,229,220); width:687px; overflow:auto; margin:18px 0px!important; padding-top:1px\">\n<div class=\"bar\" style=\"padding-left:45px\">\n<div class=\"tools\" style=\"padding:3px 8px 10px 10px; font-size:9px; line-height:normal; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; color:silver; background-color:rgb(248,248,248); border-left-width:3px; border-left-style:solid; border-left-color:rgb(153,153,153)\">\n<a href=\"http:\/\/blog.csdn.net\/v_july_v\/article\/details\/7041827#\" class=\"ViewSource\" title=\"view plain\" style=\"color:rgb(160,160,160); text-decoration:none; background-color:inherit; border:none; padding:0px; margin:0px 10px 0px 0px; font-size:9px\">view plain<\/a><\/div>\n<\/div>\n<ol class=\"dp-cpp\" start=\"1\" style=\"margin:0px 0px 1px 45px!important; padding:0px; border:none; list-style-position:initial; background-color:rgb(255,255,255); color:rgb(92,92,92)\">\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u4ee3\u78014-1&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u4fee\u6b63\u540e\u7684\u6c42next\u6570\u7ec4\u5404&#20540;\u7684\u51fd\u6570\u4ee3\u7801&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">void<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;get_nextval(<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">char<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">const<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">*&nbsp;ptrn,&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;plen,&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">*&nbsp;nextval)&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">{&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;i&nbsp;=&nbsp;0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;nextval[i]&nbsp;=&nbsp;-1;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;j&nbsp;=&nbsp;-1;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">while<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">(&nbsp;i&nbsp;&lt;&nbsp;plen-1&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">if<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">(&nbsp;j&nbsp;==&nbsp;-1&nbsp;||&nbsp;ptrn[i]&nbsp;==&nbsp;ptrn[j]&nbsp;)&nbsp;&nbsp;&nbsp;<\/span><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u5faa\u73af\u7684if\u90e8\u5206&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#43;&#43;i;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#43;&#43;j;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u4fee\u6b63\u7684\u5730\u65b9\u5c31\u53d1\u751f\u4e0b\u9762\u8fd94\u884c&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">if<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">(&nbsp;ptrn[i]&nbsp;!=&nbsp;ptrn[j]&nbsp;)&nbsp;<\/span><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/&#43;&#43;i\uff0c&#43;&#43;j\u4e4b\u540e\uff0c\u518d\u6b21\u5224\u65adptrn[i]\u4e0eptrn[j]\u7684\u5173\u7cfb&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nextval[i]&nbsp;=&nbsp;j;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u4e4b\u524d\u7684\u9519\u8bef\u89e3\u6cd5\u5c31\u5728\u4e8e\u6574\u4e2a\u5224\u65ad\u53ea\u6709\u8fd9\u4e00\u53e5\u3002&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">else<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nextval[i]&nbsp;=&nbsp;nextval[j];&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">else<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u5faa\u73af\u7684else\u90e8\u5206&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j&nbsp;=&nbsp;nextval[j];&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">}&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<\/ol>\n<\/div>\n<\/div>\n<blockquote class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<p><span style=\"font-size:13px\">&nbsp;&nbsp;&nbsp; \u4e3e\u4e2a\u4f8b\u5b50\uff0c\u4e3e\u4f8b\u8bf4\u660e\u4e0b\u4e0a\u8ff0\u6c42next\u6570\u7ec4\u7684\u65b9\u6cd5\u3002<br \/>\nS a b a b a b c<br \/>\nP a b a b c<br \/>\nS[4] != P[4]<br \/>\n&nbsp;&nbsp;&nbsp; \u90a3\u4e48\u4e0b\u4e00\u4e2a\u548cS[4]\u5339\u914d\u7684\u4f4d\u7f6e\u662fk=2(\u4e5f\u5373P[next[4]])\u3002\u6b64\u5904\u7684k=2\u4e5f\u518d\u6b21\u4f50\u8bc1\u4e86\u4e0a\u6587\u7b2c3\u8282\u5f00\u5934\u5904\u5173\u4e8e\u4e3a\u4e86\u627e\u5230\u4e0b\u4e00\u4e2a\u5339\u914d\u7684\u4f4d\u7f6e\u65f6k\u7684\u6c42\u6cd5\u3002\u4e0a\u9762\u7684\u4e3b\u4e32\u4e0e\u6a21\u5f0f\u4e32\u5f00\u59344\u4e2a\u5b57\u7b26\u90fd\u662f\u201cabab\u201d\uff0c\u6240\u4ee5\uff0c\u5339\u914d\u5931\u6548\u540e\u4e0b\u4e00\u4e2a\u5339\u914d\u7684\u4f4d\u7f6e\u76f4\u63a5\u8df3\u4e24\u6b65\u7ee7\u7eed\u8fdb\u884c\u5339\u914d\u3002<br \/>\nS a b a b a b c<br \/>\nP&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a b a b c<br \/>\n\u5339\u914d\u6210\u529f<\/span><\/p>\n<p><span style=\"font-size:13px\">P\u7684next\u6570\u7ec4&#20540;\u5206\u522b\u4e3a-1 0 -1 0 2<\/span><\/p>\n<p><span style=\"font-size:13px\">&nbsp;&nbsp;&nbsp; next\u6570\u7ec4\u5404&#20540;\u600e\u4e48\u6c42\u51fa\u6765\u7684\u5462?\u5206\u4ee5\u4e0b\u4e94\u6b65\uff1a<\/span><\/p>\n<ol>\n<li><span style=\"font-size:13px\">\u521d\u59cb\u5316\uff1ai=0\uff0cj=-1\uff0c<strong>nextval[0] = -1<\/strong>\u3002<span style=\"font-size:14px\">\u7531\u4e8ej == -1\uff0c\u8fdb\u5165\u4e0a\u8ff0\u5faa\u73af\u7684if\u90e8\u5206\uff0c&#43;&#43;i\u5f97i=1\uff0c&#43;&#43;j\u5f97j=0\uff0c\u4e14ptrn[i] != ptrn[j]\uff08\u5373a\uff01=b\uff09\uff09\uff0c\u6240\u4ee5\u5f97\u5230\u7b2c\u4e8c\u4e2anext&#20540;\u5373nextval[1] = 0\uff1b<\/span>\uff1b<\/span><\/li>\n<li><span style=\"font-size:13px\">i=1\uff0cj=0\uff0c\u8fdb\u5165\u5faa\u73afesle\u90e8\u5206\uff0c<\/span><span style=\"font-size:13px\">j=nextval[j]=nextval[0]=-1\uff1b<\/span><\/li>\n<li><span style=\"font-size:13px\">\u8fdb\u5165\u5faa\u73af\u7684if\u90e8\u5206\uff0c&#43;&#43;i\uff0c&#43;&#43;j\uff0ci=2\uff0cj=0\uff0c\u56e0\u4e3aptrn[i]=ptrn[j]=a,\u6240\u4ee5nextval[2]=nextval[0]=-1\uff1b<\/span><\/li>\n<li><span style=\"font-size:13px\">i=2, j=0, \u7531\u4e8eptrn[i]=ptrn[j],\u518d\u6b21\u8fdb\u5165\u5faa\u73afif\u90e8\u5206\uff0c\u6240\u4ee5&#43;&#43;i=3\uff0c&#43;&#43;j=1,\u56e0\u4e3aptrn[i]=ptrn[j]=b,\u6240\u4ee5nextval[3]=nextval[1]=0\uff1b<\/span><\/li>\n<li><span style=\"font-size:13px\">i=3,j=1,\u7531\u4e8eptrn[i]=ptrn[j]=b,\u6240\u4ee5&#43;&#43;i=4\uff0c&#43;&#43;j=2,\u9000\u51fa\u5faa\u73af\u3002<\/span><\/li>\n<\/ol>\n<\/blockquote>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; \u8fd9\u6837\u4e0a\u4f8b\u4e2d\u6a21\u5f0f\u4e32\u7684next\u6570\u7ec4\u5404&#20540;\u6700\u7ec8\u5e94\u8be5\u4e3a:<\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/8394323_1308075858HK8k.jpg\" height=\"104\" width=\"273\" style=\"border:none\" \/><\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color:rgb(51,51,153)\">&nbsp;&nbsp;&nbsp;&nbsp; \u56fe4-1 \u6b63\u786e\u7684next\u6570\u7ec4\u5404&#20540;<br \/>\n<\/span><strong>next\u6570\u7ec4\u6c42\u89e3\u7684\u5177\u4f53\u8fc7\u7a0b\u5982\u4e0b\uff1a<br \/>\n<\/strong>&nbsp;&nbsp;&nbsp; \u521d\u59cb\u5316\uff1anextval[0] = -1\uff0c\u6211\u4eec\u5f97\u5230\u7b2c\u4e00\u4e2anext&#20540;\u5373-1.<\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/8394323_1308075858aNNR.jpg\" height=\"84\" width=\"277\" style=\"border:none\" \/><\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color:rgb(51,51,153)\">&nbsp; \u56fe4-2 \u521d\u59cb\u5316\u7b2c\u4e00\u4e2anext&#20540;\u5373-1<\/span><\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; i = 0\uff0cj = -1\uff0c\u7531\u4e8ej == -1\uff0c\u8fdb\u5165\u4e0a\u8ff0\u5faa\u73af\u7684if\u90e8\u5206\uff0c&#43;&#43;i\u5f97i=1\uff0c&#43;&#43;j\u5f97j=0\uff0c\u4e14ptrn[i] != ptrn[j]\uff08\u5373a\uff01=b\uff09\uff09\uff0c\u6240\u4ee5\u5f97\u5230\u7b2c\u4e8c\u4e2anext&#20540;\u5373nextval[1] = 0\uff1b<\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/8394323_1308075858mc76.jpg\" height=\"95\" width=\"288\" style=\"border:none\" \/><\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color:rgb(51,51,153)\">\u56fe4-3 \u7b2c\u4e8c\u4e2anext&#20540;0<\/span><\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp; \u4e0a\u9762\u6211\u4eec\u5df2\u7ecf\u5f97\u5230\uff0ci= 1\uff0cj = 0\uff0c\u7531\u4e8e\u4e0d\u6ee1\u8db3\u6761\u4ef6j == -1 || ptrn[i] == ptrn[j]\uff0c\u6240\u4ee5\u8fdb\u5165\u5faa\u73af\u7684esle\u90e8\u5206\uff0c\u5f97j = nextval[j] = -1\uff1b\u6b64\u65f6\uff0c\u4ecd\u6ee1\u8db3\u5faa\u73af\u6761\u4ef6\uff0c\u7531\u4e8ei = 1\uff0cj = -1\uff0c\u56e0\u4e3aj == -1\uff0c\u518d\u6b21\u8fdb\u5165\u5faa\u73af\u7684if\u90e8\u5206\uff0c&#43;&#43;i\u5f97i=2\uff0c&#43;&#43;j\u5f97j=0\uff0c\u7531\u4e8eptrn[i] == ptrn[j]\uff08\u5373ptrn[2]=ptrn[0]\uff0c\u4e5f\u5c31\u662f\u8bf4\u7b2c1\u4e2a\u5143\u7d20\u548c\u7b2c\u4e09\u4e2a\u5143\u7d20\u90fd\u662fa\uff09\uff0c\u6240\u4ee5\u8fdb\u5165\u5faa\u73afif\u90e8\u5206\u5185\u5d4c\u7684else\u90e8\u5206\uff0c\u5f97\u5230nextval[2] = nextval[0]<br \/>\n = -1\uff1b<\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/8394323_1308075858ljso.jpg\" height=\"92\" width=\"266\" style=\"border:none\" \/><\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp;<span style=\"color:rgb(51,51,153)\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u56fe4-4 \u7b2c\u4e09\u4e2anext\u6570\u7ec4\u5143\u7d20&#20540;-1<\/span><\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; i = 2\uff0cj = 0\uff0c\u7531\u4e8eptrn[i] == ptrn[j]\uff0c\u8fdb\u5165if\u90e8\u5206\uff0c&#43;&#43;i\u5f97i=3\uff0c&#43;&#43;j\u5f97j=1\uff0c\u6240\u4ee5ptrn[i] == ptrn[j]\uff08ptrn[3]==ptrn[1]\uff0c\u4e5f\u5c31\u662f\u8bf4\u7b2c2\u4e2a\u5143\u7d20\u548c\u7b2c4\u4e2a\u5143\u7d20\u90fd\u662fb\uff09\uff0c\u6240\u4ee5\u8fdb\u5165\u5faa\u73afif\u90e8\u5206\u5185\u5d4c\u7684else\u90e8\u5206\uff0c\u5f97\u5230nextval[3] = nextval[1] = 0\uff1b<\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/8394323_13080758581C1S.jpg\" height=\"96\" width=\"266\" style=\"border:none\" \/><\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color:rgb(51,51,153)\">\u56fe4-5 \u7b2c\u56db\u4e2a\u6570\u7ec4\u5143\u7d20&#20540;0<br \/>\n<\/span>&nbsp;&nbsp;&nbsp; \u5982\u679c\u4f60\u8fd8\u662f\u6ca1\u6709\u5f04\u61c2\u4e0a\u8ff0\u8fc7\u7a0b\u662f\u600e\u4e48\u4e00\u56de\u4e8b\uff0c\u8bf7\u73b0\u5728\u62ff\u51fa\u4e00\u5f20\u7eb8\u548c\u4e00\u652f\u7b14\u51fa\u6765\uff0c\u4e00\u6b65\u4e00\u6b65\u7684\u753b\u4e0b\u4e0a\u8ff0\u8fc7\u7a0b\u3002\u76f8\u4fe1\u6211\uff0c\u628a\u56fe\u753b\u51fa\u6765\u4e86\u4e4b\u540e\uff0c\u4f60\u4e00\u5b9a\u80fd\u660e\u767d\u5b83\u7684\u3002<br \/>\n&nbsp;&nbsp;&nbsp; \u7136\u540e\uff0c\u6211\u7559\u4e00\u4e2a\u95ee\u9898\u7ed9\u8bfb\u8005\uff0c\u4e3a\u4ec0\u4e48\u4e0a\u8ff0\u7684next\u6570\u7ec4\u8981\u90a3\u4e48\u6c42?\u6709\u4ec0\u4e48\u539f\u7406\u4e48?<\/p>\n<p class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color:rgb(204,0,0)\">\u63d0\u793a<\/span>\uff1a\u6211\u4eec\u4ece\u4e0a\u8ff0\u5b57\u7b26\u4e32abab \u5404\u5b57\u7b26\u7684next&#20540;<u>-1 0 -1 0<\/u>\uff0c\u53ef\u4ee5\u770b\u51fa\u6765\uff0c\u6839\u636e\u6c42\u5f97\u7684next\u6570\u7ec4&#20540;\uff0c\u5077\u7528\u524d\u7f00\u3001\u540e\u7f00\u7684\u6982\u5ff5\uff0c\u4e00\u5b9a\u53ef\u4ee5\u5224\u65ad\u51fa\u5728abab\u4e4b\u4e2d\uff0c\u524d\u7f00\u548c\u540e\u7f00\u76f8\u540c\uff0c\u5373\u90fd\u662fab\uff0c\u53cd\u8fc7\u6765\uff0c\u5982\u679c\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u524d\u7f00\u548c\u540e\u7f00\u76f8\u540c\uff0c\u90a3\u4e48\u6839\u636e\u524d\u7f00\u548c\u540e\u7f00\u4f9d\u6b21\u6c42\u5f97\u7684next\u5404&#20540;\u4e5f\u662f\u76f8\u540c\u7684\u3002<\/p>\n<div class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<ul>\n<li><strong><span style=\"font-size:16px\">5\u3001\u5229\u7528\u6c42\u5f97\u7684next\u6570\u7ec4\u5404&#20540;\u8fd0\u7528Kmp\u7b97\u6cd5<\/span><\/strong><\/li>\n<\/ul>\n<\/div>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; Ok\uff0cnext\u6570\u7ec4\u5404&#20540;\u5df2\u7ecf\u6c42\u5f97\uff0c\u4e07\u4e8b\u4ff1\u5907\uff0c\u4e1c\u98ce\u4e5f\u4e0d\u6b20\u4e86\u3002\u63a5\u4e0b\u6765\uff0c\u54b1\u4eec\u5c31\u8981\u5e94\u7528\u6c42\u5f97\u7684next&#20540;\uff0c\u5e94\u7528KMP\u7b97\u6cd5\u6765\u5339\u914d\u5b57\u7b26\u4e32\u4e86\u3002\u8fd8\u8bb0\u5f97KMP\u7b97\u6cd5\u662f\u600e\u4e48\u4e00\u56de\u4e8b\u5417?\u5bb9\u6211\u518d\u6b21\u5f15\u7528\u4e0b\u4e4b\u524d\u7684KMP\u7b97\u6cd5\u7684\u4ee3\u7801\uff0c\u5982\u4e0b\uff1a<br \/>\n<span style=\"font-family:monospace; font-size:13px\"><span style=\"white-space:pre-wrap\"><\/span><\/span><\/p>\n<div class=\"dp-highlighter bg_cpp\" style=\"font-family:Consolas,'Courier New',Courier,mono,serif; background-color:rgb(231,229,220); width:687px; overflow:auto; margin:18px 0px!important; padding-top:1px; color:rgb(51,51,51); line-height:26px; text-align:left\">\n<div class=\"bar\" style=\"padding-left:45px\">\n<div class=\"tools\" style=\"padding:3px 8px 10px 10px; font-size:9px; line-height:normal; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; color:silver; background-color:rgb(248,248,248); border-left-width:3px; border-left-style:solid; border-left-color:rgb(153,153,153)\">\n<a href=\"http:\/\/blog.csdn.net\/v_july_v\/article\/details\/7041827#\" class=\"ViewSource\" title=\"view plain\" style=\"color:rgb(160,160,160); text-decoration:none; background-color:inherit; border:none; padding:0px; margin:0px 10px 0px 0px; font-size:9px\">view plain<\/a><\/div>\n<\/div>\n<ol class=\"dp-cpp\" start=\"1\" style=\"margin:0px 0px 1px 45px!important; padding:0px; border:none; list-style-position:initial; background-color:rgb(255,255,255); color:rgb(92,92,92)\">\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u4ee3\u78015-1&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/int&nbsp;kmp_seach(char&nbsp;const*,&nbsp;int,&nbsp;char&nbsp;const*,&nbsp;int,&nbsp;int&nbsp;const*,&nbsp;int&nbsp;pos)&nbsp;&nbsp;KMP\u6a21\u5f0f\u5339\u914d\u51fd\u6570&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u8f93\u5165\uff1asrc,&nbsp;slen\u4e3b\u4e32&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u8f93\u5165\uff1apatn,&nbsp;plen\u6a21\u5f0f\u4e32&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u8f93\u5165\uff1anextval&nbsp;KMP\u7b97\u6cd5\u4e2d\u7684next\u51fd\u6570&#20540;\u6570\u7ec4&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;kmp_search(<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">char<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">const<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">*&nbsp;src,&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;slen,&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">char<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">const<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">*&nbsp;patn,&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;plen,&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">const<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">*&nbsp;nextval,&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;pos)&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">{&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;i&nbsp;=&nbsp;pos;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;j&nbsp;=&nbsp;0;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">while<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;(&nbsp;i&nbsp;&lt;&nbsp;slen&nbsp;&amp;&amp;&nbsp;j&nbsp;&lt;&nbsp;plen&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">if<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">(&nbsp;j&nbsp;==&nbsp;-1&nbsp;||&nbsp;src[i]&nbsp;==&nbsp;patn[j]&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#43;&#43;i;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#43;&#43;j;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">else<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j&nbsp;=&nbsp;nextval[j];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u5f53\u5339\u914d\u5931\u8d25\u7684\u65f6\u5019\u76f4\u63a5\u7528p[j_next]\u4e0es[i]\u6bd4\u8f83\uff0c&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u4e0b\u9762\u9610\u8ff0\u600e\u4e48\u6c42\u8fd9\u4e2a&#20540;\uff0c\u5373\u5339\u914d\u5931\u6548\u540e\u4e0b\u4e00\u6b21\u5339\u914d\u7684\u4f4d\u7f6e&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">if<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">(&nbsp;j&nbsp;&gt;=&nbsp;plen&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">return<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;i-plen;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">else<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">return<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;-1;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">}&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<\/ol>\n<\/div>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n\u6211\u4eec\u4e0a\u9762\u5df2\u7ecf\u6c42\u5f97\u7684next&#20540;\uff0c\u5982\u4e0b\uff1a<\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left; padding-left:30px\">\n<img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/8394323_13080758581C1S.jpg\" height=\"96\" width=\"266\" style=\"border:none\" \/><\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left; padding-left:30px\">\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color:rgb(51,51,153)\">\u56fe5-1 \u6c42\u5f97\u7684\u6b63\u786e\u7684next\u6570\u7ec4\u5143\u7d20\u5404&#20540;<\/span><\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; \u4ee5\u4e0b\u662f\u5339\u914d\u8fc7\u7a0b\uff0c\u5206\u4e09\u6b65\uff1a<br \/>\n&nbsp;&nbsp;&nbsp; \u7b2c\u4e00\u6b65\uff1a\u4e3b\u4e32\u548c\u6a21\u5f0f\u4e32\u5982\u4e0b\uff0cS[3]\u4e0eP[3]\u5339\u914d\u5931\u8d25\u3002<\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/8394323_130807585714lW.jpg\" height=\"159\" width=\"417\" style=\"border:none\" \/><\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color:rgb(51,51,153)\">\u56fe5-2 \u7b2c\u4e00\u6b65\uff0cS[3]\u4e0eP[3]\u5339\u914d\u5931\u8d25<br \/>\n<\/span>&nbsp;&nbsp;&nbsp; \u7b2c\u4e8c\u6b65\uff1aS[3]\u4fdd\u6301\u4e0d\u53d8\uff0cP\u7684\u4e0b\u4e00\u4e2a\u5339\u914d\u4f4d\u7f6e\u662fP[next[3]]\uff0c\u800cnext[3]=0,\u6240\u4ee5P[next[3]]=P[0]\uff0c\u5373P[0]\u4e0eS[3]\u5339\u914d\u3002\u5728P[0]\u4e0eS[3]\u5904\u5339\u914d\u5931\u8d25\u3002<\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/8394323_13080758571390.jpg\" height=\"176\" width=\"495\" style=\"border:none\" \/><\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color:rgb(51,51,153)\">\u56fe5-3 \u7b2c\u4e8c\u6b65\uff0c\u5728P[0]\u4e0eS[3]\u5904\u5339\u914d\u5931\u8d25<\/span><\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; \u7b2c\u4e09\u6b65\uff1a\u4e0e\u4e0a\u6587\u4e2d\u7b2c3\u5c0f\u8282\u672b\u7684\u60c5\u51b5\u4e00\u81f4\u3002\u7531\u4e8e\u4e0a\u8ff0\u7b2c\u4e09\u6b65\u4e2d\uff0cP[0]\u4e0eS[3]\u8fd8\u662f\u4e0d\u5339\u914d\u3002\u6b64\u65f6i=3,j=nextval[0]=-1,\u7531\u4e8e\u6ee1\u8db3\u6761\u4ef6j==-1\uff0c\u6240\u4ee5\u8fdb\u5165\u5faa\u73af\u7684if\u90e8\u5206,&#43;&#43;i=4,&#43;&#43;j=0,\u5373\u4e3b\u4e32\u6307\u9488\u4e0b\u79fb\u4e00\u4e2a\u4f4d\u7f6e\uff0c\u4eceP[0]\u4e0eS[4]\u5904\u5f00\u59cb\u5339\u914d\u3002\u6700\u540ej==plen\uff0c\u8df3\u51fa\u5faa\u73af\uff0c\u8f93\u51fa\u7ed3\u679ci-plen=4(\u5373\u5b57\u4e32\u7b2c\u4e00\u6b21\u51fa\u73b0\u7684\u4f4d\u7f6e\uff09\uff0c\u5339\u914d\u6210\u529f\uff0c\u7b97\u6cd5\u7ed3\u675f\u3002<\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/8394323_1308075857e40u.jpg\" height=\"167\" width=\"451\" style=\"border:none\" \/><\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color:rgb(51,51,153)\">\u56fe5-4 \u7b2c\u4e09\u6b65\uff0c\u5339\u914d\u6210\u529f\uff0c\u7b97\u6cd5\u7ed3\u675f<br \/>\n<\/span>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"text-decoration:underline\">\u6240\u4ee5\uff0c\u7efc\u4e0a\uff0c\u603b\u7ed3\u4e0a\u8ff0\u4e09\u6b65\u4e3a<\/span>\uff1a<\/p>\n<ol style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<li>\u5f00\u59cb\u5339\u914d\uff0c\u76f4\u5230P[3]\uff01=S[3]\uff0c\u5339\u914d\u5931\u8d25\uff1b<\/li>\n<li>nextval[3]=0\uff0c\u6240\u4ee5P[0]\u7ee7\u7eed\u4e0eS[3]\u5339\u914d\uff0c\u518d\u6b21\u5339\u914d\u5931\u8d25\uff1b<\/li>\n<li>nextval[0]=-1\uff0c\u6ee1\u8db3\u5faa\u73afif\u90e8\u5206\u6761\u4ef6j==-1\uff0c\u6240\u4ee5\uff0c&#43;&#43;i\uff0c&#43;&#43;j\uff0c\u4e3b\u4e32\u6307\u9488\u4e0b\u79fb\u4e00\u4e2a\u4f4d\u7f6e\uff0c\u4eceP[0]\u4e0eS[4]\u5904\u5f00\u59cb\u5339\u914d\uff0c\u6700\u540ej==plen\uff0c\u8df3\u51fa\u5faa\u73af\uff0c\u8f93\u51fa\u7ed3\u679ci-plen=4\uff0c\u7b97\u6cd5\u7ed3\u675f\u3002<\/li>\n<\/ol>\n<h3 style=\"margin:0px; padding:0px; color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left\">\n<a name=\"t3\" style=\"color:rgb(51,102,153)\"><\/a>\u7b2c\u4e09\u90e8\u5206\u3001KMP\u7b97\u6cd5\u7684\u4e24\u79cd\u5b9e\u73b0<\/h3>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<strong>\u4ee3\u7801\u5b9e\u73b0\u4e00\uff1a<\/strong>&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; \u6839\u636e\u4e0a\u6587\u4e2d\u7b2c\u4e8c\u90e8\u5206\u5185\u5bb9\u7684\u89e3\u6790\uff0c\u5b8c\u6574\u5199\u51faKMP\u7b97\u6cd5\u7684\u4ee3\u7801\u5df2\u7ecf\u4e0d\u662f\u96be\u4e8b\u4e86\uff0c\u5982\u4e0b\uff1a<\/p>\n<div class=\"dp-highlighter bg_cpp\" style=\"font-family:Consolas,'Courier New',Courier,mono,serif; background-color:rgb(231,229,220); width:687px; overflow:auto; margin:18px 0px!important; padding-top:1px; color:rgb(51,51,51); line-height:26px; text-align:left\">\n<div class=\"bar\" style=\"padding-left:45px\">\n<div class=\"tools\" style=\"padding:3px 8px 10px 10px; font-size:9px; line-height:normal; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; color:silver; background-color:rgb(248,248,248); border-left-width:3px; border-left-style:solid; border-left-color:rgb(153,153,153)\">\n<a href=\"http:\/\/blog.csdn.net\/v_july_v\/article\/details\/7041827#\" class=\"ViewSource\" title=\"view plain\" style=\"color:rgb(160,160,160); text-decoration:none; background-color:inherit; border:none; padding:0px; margin:0px 10px 0px 0px; font-size:9px\">view plain<\/a><\/div>\n<\/div>\n<ol class=\"dp-cpp\" start=\"1\" style=\"margin:0px 0px 1px 45px!important; padding:0px; border:none; list-style-position:initial; background-color:rgb(255,255,255); color:rgb(92,92,92)\">\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/copyright@2011&nbsp;binghu&nbsp;and&nbsp;july<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"preprocessor\" style=\"margin:0px; padding:0px; border:none; color:gray; background-color:inherit\">#include&nbsp;&quot;StdAfx.h&quot;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"preprocessor\" style=\"margin:0px; padding:0px; border:none; color:gray; background-color:inherit\">#include&nbsp;&lt;string&gt;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"preprocessor\" style=\"margin:0px; padding:0px; border:none; color:gray; background-color:inherit\">#include&nbsp;&lt;iostream&gt;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">using<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">namespace<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;std;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u4ee3\u78014-1&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u4fee\u6b63\u540e\u7684\u6c42next\u6570\u7ec4\u5404&#20540;\u7684\u51fd\u6570\u4ee3\u7801&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">void<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;get_nextval(<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">char<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">const<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">*&nbsp;ptrn,&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;plen,&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">*&nbsp;nextval)&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">{&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;i&nbsp;=&nbsp;0;&nbsp;&nbsp;<\/span><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u6ce8\uff0c\u6b64\u5904\u4e0e\u4e0b\u6587\u7684\u4ee3\u7801\u5b9e\u73b0\u4e8c\u4e0d\u540c\u7684\u662f\uff0ci\u662f\u4ece0\u5f00\u59cb\u7684\uff08\u4ee3\u7801\u5b9e\u73b0\u4e8ci\u4ece1\u5f00\u59cb\uff09&nbsp;&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;nextval[i]&nbsp;=&nbsp;-1;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;j&nbsp;=&nbsp;-1;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">while<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">(&nbsp;i&nbsp;&lt;&nbsp;plen-1&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">if<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">(&nbsp;j&nbsp;==&nbsp;-1&nbsp;||&nbsp;ptrn[i]&nbsp;==&nbsp;ptrn[j]&nbsp;)&nbsp;&nbsp;&nbsp;<\/span><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u5faa\u73af\u7684if\u90e8\u5206&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#43;&#43;i;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#43;&#43;j;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u4fee\u6b63\u7684\u5730\u65b9\u5c31\u53d1\u751f\u4e0b\u9762\u8fd94\u884c&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">if<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">(&nbsp;ptrn[i]&nbsp;!=&nbsp;ptrn[j]&nbsp;)&nbsp;<\/span><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/&#43;&#43;i\uff0c&#43;&#43;j\u4e4b\u540e\uff0c\u518d\u6b21\u5224\u65adptrn[i]\u4e0eptrn[j]\u7684\u5173\u7cfb&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nextval[i]&nbsp;=&nbsp;j;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u4e4b\u524d\u7684\u9519\u8bef\u89e3\u6cd5\u5c31\u5728\u4e8e\u6574\u4e2a\u5224\u65ad\u53ea\u6709\u8fd9\u4e00\u53e5\u3002&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">else<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nextval[i]&nbsp;=&nbsp;nextval[j];&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">else<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u5faa\u73af\u7684else\u90e8\u5206&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j&nbsp;=&nbsp;nextval[j];&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">}&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">void<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;print_progress(<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">char<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">const<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">*&nbsp;src,&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;src_index,&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">char<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">const<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">*&nbsp;pstr,&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;pstr_index)&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">{&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;src_index&lt;&lt;<span class=\"string\" style=\"margin:0px; padding:0px; border:none; color:red; background-color:inherit\">&quot;t&quot;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&lt;&lt;src&lt;&lt;endl;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;pstr_index&lt;&lt;<span class=\"string\" style=\"margin:0px; padding:0px; border:none; color:red; background-color:inherit\">&quot;t&quot;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">for<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">(&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;src_index-pstr_index;&nbsp;&#43;&#43;i&nbsp;)&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;<span class=\"string\" style=\"margin:0px; padding:0px; border:none; color:red; background-color:inherit\">&quot;&nbsp;&quot;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;pstr&lt;&lt;endl;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;endl;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">}&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u4ee3\u78015-1&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/int&nbsp;kmp_seach(char&nbsp;const*,&nbsp;int,&nbsp;char&nbsp;const*,&nbsp;int,&nbsp;int&nbsp;const*,&nbsp;int&nbsp;pos)&nbsp;&nbsp;KMP\u6a21\u5f0f\u5339\u914d\u51fd\u6570&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u8f93\u5165\uff1asrc,&nbsp;slen\u4e3b\u4e32&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u8f93\u5165\uff1apatn,&nbsp;plen\u6a21\u5f0f\u4e32&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u8f93\u5165\uff1anextval&nbsp;KMP\u7b97\u6cd5\u4e2d\u7684next\u51fd\u6570&#20540;\u6570\u7ec4&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;kmp_search(<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">char<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">const<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">*&nbsp;src,&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;slen,&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">char<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">const<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">*&nbsp;patn,&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;plen,&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">const<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">*&nbsp;nextval,&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;pos)&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">{&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;i&nbsp;=&nbsp;pos;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;j&nbsp;=&nbsp;0;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">while<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;(&nbsp;i&nbsp;&lt;&nbsp;slen&nbsp;&amp;&amp;&nbsp;j&nbsp;&lt;&nbsp;plen&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">if<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">(&nbsp;j&nbsp;==&nbsp;-1&nbsp;||&nbsp;src[i]&nbsp;==&nbsp;patn[j]&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#43;&#43;i;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#43;&#43;j;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">else<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j&nbsp;=&nbsp;nextval[j];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u5f53\u5339\u914d\u5931\u8d25\u7684\u65f6\u5019\u76f4\u63a5\u7528p[j_next]\u4e0es[i]\u6bd4\u8f83\uff0c&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u4e0b\u9762\u9610\u8ff0\u600e\u4e48\u6c42\u8fd9\u4e2a&#20540;\uff0c\u5373\u5339\u914d\u5931\u6548\u540e\u4e0b\u4e00\u6b21\u5339\u914d\u7684\u4f4d\u7f6e&nbsp;&nbsp;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">if<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">(&nbsp;j&nbsp;&gt;=&nbsp;plen&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">return<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;i-plen;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">else<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">return<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;-1;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">}&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;&nbsp;main()&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">{&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;std::string&nbsp;src&nbsp;=&nbsp;<span class=\"string\" style=\"margin:0px; padding:0px; border:none; color:red; background-color:inherit\">&quot;aabcabcebafabcabceabcaefabcacdabcab&quot;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;std::string&nbsp;prn&nbsp;=&nbsp;<span class=\"string\" style=\"margin:0px; padding:0px; border:none; color:red; background-color:inherit\">&quot;abac&quot;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">*&nbsp;nextval&nbsp;=&nbsp;<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">new<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">[prn.size()];&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/int*&nbsp;next&nbsp;=&nbsp;new&nbsp;int[prn.size()];<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;get_nextval(prn.data(),&nbsp;prn.size(),&nbsp;nextval);&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/get_next(prn.data(),&nbsp;prn.size(),&nbsp;next);<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">for<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">(&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;prn.size();&nbsp;&#43;&#43;i&nbsp;)&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;nextval[i]&lt;&lt;<span class=\"string\" style=\"margin:0px; padding:0px; border:none; color:red; background-color:inherit\">&quot;t&quot;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;endl;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;<span class=\"string\" style=\"margin:0px; padding:0px; border:none; color:red; background-color:inherit\">&quot;result&nbsp;sub&nbsp;str:&nbsp;&quot;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&lt;&lt;src.substr(&nbsp;kmp_search(src.data(),&nbsp;src.size(),&nbsp;prn.data(),&nbsp;prn.size(),&nbsp;nextval,&nbsp;0)&nbsp;)&lt;&lt;endl;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;system(<span class=\"string\" style=\"margin:0px; padding:0px; border:none; color:red; background-color:inherit\">&quot;pause&quot;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">);&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">delete<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">[]&nbsp;nextval;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">return<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;0;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">}&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<\/ol>\n<\/div>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; \u8fd0\u884c\u7ed3\u679c\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<img decoding=\"async\" alt=\"\" src=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/0_1323314920mQh4.gif\" style=\"border:none\" \/><\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<strong>\u4ee3\u7801\u5b9e\u73b0\u4e8c<\/strong>\uff1a<\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp;&nbsp; \u518d\u7ed9\u51fa\u4ee3\u7801\u5b9e\u73b0\u4e8c\u4e4b\u524d\uff0c\u8ba9\u6211\u4eec\u518d\u6b21<span style=\"font-size:18px\">\u56de\u987e\u4e0b\u5173\u4e8eKMP\u7b97\u6cd5\u7684\u7b2c\u4e00\u7bc7\u6587\u7ae0\u4e2d\u7684\u90e8\u5206\u5185\u5bb9<\/span>\uff1a<\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<span style=\"font-size:24px\"><strong>\u201c<\/strong><\/span><span style=\"font-size:13px\"><span style=\"font-size:16px\">\u7b2c\u4e8c\u8282\u3001KMP\u7b97\u6cd5<\/span><\/span><\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<strong><span style=\"color:black\"><span style=\"font-family:Calibri\">2.1\u3001&nbsp;<\/span><\/span><span style=\"font-family:\u5b8b\u4f53; color:black\">\u8986\u76d6\u51fd\u6570<\/span><span style=\"color:black\"><span style=\"font-family:Calibri\">(overlay_function)<\/span><\/span><\/strong><\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; \u8986\u76d6\u51fd\u6570\u6240\u8868\u5f81\u7684\u662fpattern\u672c\u8eab\u7684\u6027\u8d28\uff0c\u53ef\u4ee5\u8ba9\u4e3a\u5176\u8868\u5f81\u7684\u662fpattern\u4ece\u5de6\u5f00\u59cb\u7684\u6240\u6709\u8fde\u7eed\u5b50\u4e32\u7684\u81ea\u6211\u8986\u76d6\u7a0b\u5ea6\u3002\u6bd4\u5982\u5982\u4e0b\u7684\u5b57\u4e32\uff0cabaabcaba<\/p>\n<blockquote dir=\"ltr\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left; margin-right:0px\">\n<blockquote dir=\"ltr\" style=\"margin-right:0px\">\n<blockquote dir=\"ltr\" style=\"margin-right:0px\">\n<blockquote dir=\"ltr\" style=\"margin-right:0px\">\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/8394323_1293874441hilM.jpg\" height=\"294\" width=\"236\" style=\"border:none\" \/><\/p>\n<\/blockquote>\n<\/blockquote>\n<\/blockquote>\n<\/blockquote>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp; &nbsp; \u53ef\u80fd\u4e0a\u9762\u7684\u56fe\u4ee4\u8bfb\u8005\u7406\u89e3\u8d77\u6765\u8fd8\u662f\u4e0d\u90a3\u4e48\u6e05\u6670\u6613\u61c2\uff0c\u5176\u5b9e\u5f88\u7b80\u5355\uff0c\u9488\u5bf9\u5b57\u7b26\u4e32abaabcaba<\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<span style=\"color:rgb(51,51,255)\">a\uff08-1\uff09&nbsp;<\/span><span style=\"color:rgb(51,51,255)\">b\uff08-1\uff09<\/span><span style=\"color:rgb(51,51,255)\">a\uff080\uff09<\/span><span style=\"color:rgb(51,51,255)\">&nbsp;<\/span><span style=\"color:rgb(51,51,255)\">a<\/span><span style=\"color:rgb(51,51,255); white-space:pre\">\uff08<\/span><span style=\"color:rgb(51,51,255)\">0<\/span><span style=\"color:rgb(51,51,255); white-space:pre\">\uff09<\/span><span style=\"color:rgb(51,51,255)\">&nbsp;<\/span><span style=\"color:rgb(51,51,255)\">b<\/span><span style=\"color:rgb(51,51,255); white-space:pre\">\uff081\uff09&nbsp;<\/span><span style=\"color:rgb(51,51,255)\">c\uff08-1\uff09<\/span><span style=\"color:rgb(51,51,255)\">&nbsp;<\/span><span style=\"color:rgb(51,51,255)\">a\uff080\uff09<\/span><span style=\"color:rgb(51,51,255)\">&nbsp;b\uff081\uff09<\/span><span style=\"color:rgb(51,51,255)\">a\uff082\uff09<\/span><\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<span style=\"color:rgb(51,51,255)\">\u89e3\u91ca\uff1a<\/span><\/p>\n<ol style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<li><span style=\"color:rgb(51,51,255)\">\u521d\u59cb\u5316\u4e3a-1&nbsp;<\/span><span style=\"color:rgb(51,51,255)\">&nbsp;<\/span><\/li>\n<li><span style=\"color:rgb(51,51,255)\">b\u4e0ea\u4e0d\u540c\u4e3a-1 &nbsp;&nbsp;<\/span><\/li>\n<li><span style=\"color:rgb(51,51,255)\">\u4e0e\u7b2c\u4e00\u4e2a\u5b57\u7b26a\u76f8\u540c\u4e3a0 &nbsp;&nbsp;<\/span><\/li>\n<li><span style=\"color:rgb(51,51,255)\">\u8fd8\u662fa\u4e3a0 &nbsp;&nbsp;<\/span><\/li>\n<li><span style=\"color:rgb(51,51,255)\">\u540e\u7f00ab\u4e0e\u524d\u7f00ab\u4e24\u4e2a\u5b57\u7b26\u76f8\u540c\u4e3a1&nbsp;<\/span><\/li>\n<li><span style=\"color:rgb(51,51,255)\">\u524d\u9762\u5e76\u65e0\u524d\u7f00c\u4e3a-1 &nbsp;<\/span><\/li>\n<li><span style=\"color:rgb(51,51,255)\">\u4e0e\u7b2c\u4e00\u4e2a\u5b57\u7b26\u540c\u4e3a0 &nbsp;<\/span><\/li>\n<li><span style=\"color:rgb(51,51,255)\">\u540e\u7f00ab\u524d\u7f00ab\u4e3a1&nbsp;<\/span><\/li>\n<li><span style=\"color:rgb(51,51,255)\">\u524d\u7f00aba\u540e\u7f00aba\u4e3a2<\/span><\/li>\n<\/ol>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp; &nbsp; \u7531\u4e8e\u8ba1\u6570\u662f\u4ece0\u59cb\u7684\uff0c\u56e0\u6b64\u8986\u76d6\u51fd\u6570\u7684&#20540;\u4e3a0\u8bf4\u660e\u67091\u4e2a\u5339\u914d\uff0c\u5bf9\u4e8e\u4ece0\u8fd8\u662f\u4ece\u6765\u5f00\u59cb\u8ba1\u6570\u662f\u504f\u597d\u95ee\u9898\uff0c\u5177\u4f53\u8bf7\u81ea\u884c\u8c03\u6574\uff0c\u5176\u4e2d-1\u8868\u793a\u6ca1\u6709\u8986\u76d6\uff0c\u90a3\u4e48\u4f55\u4e3a\u8986\u76d6\u5462\uff0c\u4e0b\u9762\u6bd4\u8f83\u6570\u5b66\u7684\u6765\u770b\u4e00\u4e0b\u5b9a\u4e49\uff0c\u6bd4\u5982\u5bf9\u4e8e\u5e8f\u5217<\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<div class=\"Section0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<p class=\"p0\" style=\"padding-left:30px; margin-top:0pt; margin-bottom:0pt\"><span style=\"font-family:\u5b8b\u4f53; font-size:22pt\">&nbsp; a<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:10.5pt\">0<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:22pt\">a<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:10.5pt\">1...<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:22pt\">a<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:10.5pt\">j-1&nbsp;<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:22pt\">a<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:10.5pt\">j<\/span><\/p>\n<p class=\"p0\" style=\"padding-left:30px; margin-top:0pt; margin-bottom:0pt\">\n<p><span style=\"font-family:\u5b8b\u4f53; font-size:10.5pt\"><\/span><\/p>\n<p class=\"p0\" style=\"padding-left:30px; margin-top:0pt; margin-bottom:0pt\"><span style=\"font-family:\u5b8b\u4f53; font-size:10.5pt\">\u8981\u627e\u5230\u4e00\u4e2a<span lang=\"EN-US\"><span style=\"font-family:Calibri\">k,<\/span><\/span>\u4f7f\u5b83\u6ee1\u8db3<\/span><\/p>\n<p class=\"p0\" style=\"padding-left:30px; margin-top:0pt; margin-bottom:0pt\"><span style=\"font-family:\u5b8b\u4f53; font-size:22pt\">&nbsp; a<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:10.5pt\">0<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:22pt\">a<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:10.5pt\">1...<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:22pt\">a<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:10.5pt\">k-1<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:22pt\">a<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:10.5pt\">k=<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:22pt\">a<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:10.5pt\">j-k<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:22pt\">a<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:10.5pt\">j-k&#43;1...<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:22pt\">a<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:10.5pt\">j-1<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:22pt\">a<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:10.5pt\">j<\/span><\/p>\n<\/div>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; \u800c\u6ca1\u6709\u66f4\u5927\u7684k\u6ee1\u8db3\u8fd9\u4e2a\u6761\u4ef6\uff0c\u5c31\u662f\u8bf4\u8981\u627e\u5230\u5c3d\u53ef\u80fd\u5927k,\u4f7fpattern\u524dk\u5b57\u7b26\u4e0e\u540ek\u5b57\u7b26\u76f8\u5339\u914d\uff0ck\u8981\u5c3d\u53ef\u80fd\u7684\u5927\uff0c\u539f\u56e0\u662f\u5982\u679c\u6709\u6bd4\u8f83\u5927\u7684k\u5b58\u5728\u3002<\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; \u4f46\u82e5\u6211\u4eec\u9009\u62e9\u8f83\u5c0f\u7684\u6ee1\u8db3\u6761\u4ef6\u7684k\uff0c\u90a3\u4e48\u5f53\u5931\u914d\u65f6\uff0c\u6211\u4eec\u5c31\u4f1a\u4f7fpattern\u5411\u53f3\u79fb\u52a8\u7684\u4f4d\u7f6e\u53d8\u5927\uff0c\u800c\u8f83\u5c11\u7684\u79fb\u52a8\u4f4d\u7f6e\u662f\u5b58\u5728\u5339\u914d\u7684\uff0c\u8fd9\u6837\u6211\u4eec\u5c31\u4f1a\u628a\u53ef\u80fd\u5339\u914d\u7684\u7ed3\u679c\u4e22\u5931\u3002\u6bd4\u5982\u4e0b\u9762\u7684\u5e8f\u5217\uff0c<\/p>\n<blockquote dir=\"ltr\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left; margin-right:0px\">\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/8394323_1293874442uL1u.jpg\" height=\"122\" width=\"537\" style=\"border:none\" \/><\/p>\n<\/blockquote>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; \u5728\u7ea2\u8272\u90e8\u5206\u5931\u914d\uff0c\u6b63\u786e\u7684\u7ed3\u679c\u662fk=1\u7684\u60c5\u51b5\uff0c\u628apattern\u53f3\u79fb4\u4f4d\uff0c\u5982\u679c\u9009\u62e9k=0,\u53f3\u79fb5\u4f4d\u5219\u4f1a\u4ea7\u751f\u9519\u8bef\u3002\u8ba1\u7b97\u8fd9\u4e2aoverlay\u51fd\u6570\u7684\u65b9\u6cd5\u53ef\u4ee5\u91c7\u7528\u9012\u63a8\uff0c\u53ef\u4ee5\u60f3\u8c61\u5982\u679c\u5bf9\u4e8epattern\u7684\u524dj\u4e2a\u5b57\u7b26\uff0c\u5982\u679c\u8986\u76d6\u51fd\u6570&#20540;\u4e3ak<\/p>\n<p class=\"p0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left; margin-top:0pt; margin-bottom:0pt\">\n<span style=\"font-family:\u5b8b\u4f53; font-size:22pt\">&nbsp;&nbsp;&nbsp; a<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:10.5pt\">0<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:22pt\">a<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:10.5pt\">1...<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:22pt\">a<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:10.5pt\">k-1<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:22pt\">a<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:10.5pt\">k=<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:22pt\">a<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:10.5pt\">j-k<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:22pt\">a<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:10.5pt\">j-k&#43;1...<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:22pt\">a<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:10.5pt\">j-1<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:22pt\">a<\/span><span style=\"font-family:\u5b8b\u4f53; font-size:10.5pt\">j<\/span><br \/>\n\u5219\u5bf9\u4e8epattern\u7684\u524dj&#43;1\u5e8f\u5217\u5b57\u7b26\uff0c\u5219\u6709\u5982\u4e0b\u53ef\u80fd<br \/>\n&nbsp;&nbsp;&nbsp; \u2474&nbsp;&nbsp;&nbsp;&nbsp; pattern[k&#43;1]==pattern[j&#43;1] \u6b64\u65f6overlay(j&#43;1)=k&#43;1=overlay(j)&#43;1<br \/>\n&nbsp;&nbsp;&nbsp; \u2475&nbsp;&nbsp;&nbsp;&nbsp; pattern[k&#43;1]\u2260pattern[j&#43;1] \u6b64\u65f6\u53ea\u80fd\u5728pattern\u524dk&#43;1\u4e2a\u5b50\u7b26\u7ec4\u6240\u7684\u5b50\u4e32\u4e2d\u627e\u5230\u76f8\u5e94\u7684overlay\u51fd\u6570\uff0ch=overlay(k),\u5982\u679c\u6b64\u65f6pattern[h&#43;1]==pattern[j&#43;1],\u5219overlay(j&#43;1)=h&#43;1\u5426\u5219\u91cd\u590d(2)\u8fc7\u7a0b.<\/p>\n<p class=\"p0\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left; margin-top:0pt; margin-bottom:0pt\">\n\u4e0b\u9762\u7ed9\u51fa\u4e00\u6bb5\u8ba1\u7b97\u8986\u76d6\u51fd\u6570\u7684\u4ee3\u7801\uff1a<\/p>\n<div class=\"dp-highlighter bg_cpp\" style=\"font-family:Consolas,'Courier New',Courier,mono,serif; background-color:rgb(231,229,220); width:687px; overflow:auto; margin:18px 0px!important; padding-top:1px; color:rgb(51,51,51); line-height:26px; text-align:left\">\n<div class=\"bar\" style=\"padding-left:45px\">\n<div class=\"tools\" style=\"padding:3px 8px 10px 10px; font-size:9px; line-height:normal; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; color:silver; background-color:rgb(248,248,248); border-left-width:3px; border-left-style:solid; border-left-color:rgb(153,153,153)\">\n<a href=\"http:\/\/blog.csdn.net\/v_july_v\/article\/details\/7041827#\" class=\"ViewSource\" title=\"view plain\" style=\"color:rgb(160,160,160); text-decoration:none; background-color:inherit; border:none; padding:0px; margin:0px 10px 0px 0px; font-size:9px\">view plain<\/a><\/div>\n<\/div>\n<ol class=\"dp-cpp\" start=\"1\" style=\"margin:0px 0px 1px 45px!important; padding:0px; border:none; list-style-position:initial; background-color:rgb(255,255,255); color:rgb(92,92,92)\">\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/copyright@&nbsp;staurman<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/updated@2011&nbsp;July<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"preprocessor\" style=\"margin:0px; padding:0px; border:none; color:gray; background-color:inherit\">#include&nbsp;&quot;StdAfx.h&quot;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"preprocessor\" style=\"margin:0px; padding:0px; border:none; color:gray; background-color:inherit\">#include&lt;iostream&gt;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"preprocessor\" style=\"margin:0px; padding:0px; border:none; color:gray; background-color:inherit\">#include&lt;string&gt;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">using<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">namespace<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;std;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/solve&nbsp;to&nbsp;the&nbsp;next&nbsp;array<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">void<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;compute_overlay(<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">const<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;string&amp;&nbsp;pattern)&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">{&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">const<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;pattern_length&nbsp;=&nbsp;pattern.size();&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;*overlay_function&nbsp;=&nbsp;<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">new<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">[pattern_length];&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;index;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;overlay_function[0]&nbsp;=&nbsp;-1;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">for<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">(<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;i=1;i&lt;pattern_length;&#43;&#43;i)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u6ce8\uff0c\u4e0e\u4e0a\u6587\u4ee3\u7801\u6bb5\u4e00\u4e0d\u540c\u7684\u662f\uff0c\u6b64\u5904i\u662f\u4ece1\u5f00\u59cb\u7684\uff0c\u6240\u4ee5\uff0c\u4e0b\u6587\u4e2d\u8fd0\u7528\u4fe9\u79cd\u65b9\u6cd5\u6c42\u51fa\u6765\u7684next\u6570\u7ec4\u5404&#20540;\u4f1a\u6709\u6240\u4e0d\u540c<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;index&nbsp;=&nbsp;overlay_function[i-1];&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/store&nbsp;previous&nbsp;fail&nbsp;position&nbsp;k&nbsp;to&nbsp;index;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">while<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">(index&gt;=0&nbsp;&amp;&amp;&nbsp;pattern[i]!=pattern[index&#43;1])&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;index&nbsp;=&nbsp;overlay_function[index];&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">if<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">(pattern[i]==pattern[index&#43;1])&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;overlay_function[i]&nbsp;=&nbsp;index&nbsp;&#43;&nbsp;1;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">else<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;overlay_function[i]&nbsp;=&nbsp;-1;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">for<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">(<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;i=0;i&lt;pattern_length;&#43;&#43;i)&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;overlay_function[i]&lt;&lt;endl;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">delete<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">[]&nbsp;overlay_function;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">}&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/abaabcaba<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;main()&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">{&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;string&nbsp;pattern&nbsp;=&nbsp;<span class=\"string\" style=\"margin:0px; padding:0px; border:none; color:red; background-color:inherit\">&quot;abaabcaba&quot;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;compute_overlay(pattern);&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;system(<span class=\"string\" style=\"margin:0px; padding:0px; border:none; color:red; background-color:inherit\">&quot;pause&quot;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">);&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">return<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;0;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">}&nbsp;&nbsp;<\/span><\/li>\n<\/ol>\n<\/div>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<strong>&nbsp;&nbsp;&nbsp;&nbsp;<\/strong>\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<img decoding=\"async\" alt=\"\" src=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/0_1323398212crbf.gif\" style=\"border:none\" \/><\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<strong>2.2\u3001kmp\u7b97\u6cd5<br \/>\n<\/strong>&nbsp;&nbsp;&nbsp;&nbsp; \u6709\u4e86\u8986\u76d6\u51fd\u6570\uff0c\u90a3\u4e48\u5b9e\u73b0kmp\u7b97\u6cd5\u5c31\u662f\u5f88\u7b80\u5355\u7684\u4e86\uff0c\u6211\u4eec\u7684\u539f\u5219\u8fd8\u662f\u4ece\u5de6\u5411\u53f3\u5339\u914d\uff0c\u4f46\u662f\u5f53\u5931\u914d\u53d1\u751f\u65f6\uff0c\u6211\u4eec\u4e0d\u7528\u628atarget_index\u5411\u56de\u79fb\u52a8\uff0ctarget_index\u524d\u9762\u5df2\u7ecf\u5339\u914d\u8fc7\u7684\u90e8\u5206\u5728pattern\u81ea\u8eab\u5c31\u80fd\u4f53\u73b0\u51fa\u6765\uff0c\u53ea\u8981\u52a8pattern_index\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n\u5f53\u53d1\u751f\u5728j\u957f\u5ea6\u5931\u914d\u65f6\uff0c\u53ea\u8981\u628apattern\u5411\u53f3\u79fb\u52a8j-overlay(j)\u957f\u5ea6\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp;&nbsp; \u5982\u679c\u5931\u914d\u65f6pattern_index==0\uff0c\u76f8\u5f53\u4e8epattern\u7b2c\u4e00\u4e2a\u5b57\u7b26\u5c31\u4e0d\u5339\u914d\uff0c\u8fd9\u65f6\u5c31\u5e94\u8be5\u628atarget_index\u52a01\uff0c\u5411\u53f3\u79fb\u52a81\u4f4d\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; ok\uff0c\u4e0b\u56fe\u5c31\u662fKMP\u7b97\u6cd5\u7684\u8fc7\u7a0b\uff08\u7ea2\u8272\u5373\u662f\u91c7\u7528KMP\u7b97\u6cd5\u7684\u6267\u884c\u8fc7\u7a0b\uff09\uff1a<\/p>\n<blockquote dir=\"ltr\" style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left; margin-right:0px\">\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/8394323_12938727418BHQ.jpg\" height=\"587\" width=\"602\" style=\"border:none\" \/><\/p>\n<\/blockquote>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<span style=\"font-size:13px\">&nbsp;&nbsp;&nbsp; \uff08\u53e6\u4e00\u4f5c\u8005saturnman\u53d1\u73b0\uff0c\u5728\u4e0a\u8ff0KMP\u5339\u914d\u8fc7\u7a0b\u56fe\u4e2d\uff0cindex=8\u548cindex=11\u5904\u753b\u9519\u4e86\u3002\u8fd8\u6709\uff0canaven\u4e5f\u65e9\u5df2\u53d1\u73b0\uff0cindex=3\u5904\u4e5f\u753b\u9519\u4e86\u3002\u975e\u5e38\u611f\u8c22\u3002\u4f46\u56fe\u5df2\u65e0\u6cd5\u4fee\u6539\uff0c\u89c1\u8c05\uff09<\/span><\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\nKMP \u7b97\u6cd5\u53ef\u5728O\uff08n&#43;m\uff09\u65f6\u95f4\u5185\u5b8c\u6210\u5168\u90e8\u7684\u4e32\u7684\u6a21\u5f0f\u5339\u914d\u5de5\u4f5c\u3002<strong><span style=\"font-size:24px\">\u201d<\/span><\/strong><\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; OK\uff0c\u4e0b\u9762\u6b64\u524d\u5199\u7684\u5173\u4e8eKMP\u7b97\u6cd5\u7684\u7b2c\u4e00\u7bc7\u6587\u7ae0\u4e2d\u7684\u6e90\u7801\uff1a<\/p>\n<div class=\"dp-highlighter bg_cpp\" style=\"font-family:Consolas,'Courier New',Courier,mono,serif; background-color:rgb(231,229,220); width:687px; overflow:auto; margin:18px 0px!important; padding-top:1px; color:rgb(51,51,51); line-height:26px; text-align:left\">\n<div class=\"bar\" style=\"padding-left:45px\">\n<div class=\"tools\" style=\"padding:3px 8px 10px 10px; font-size:9px; line-height:normal; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; color:silver; background-color:rgb(248,248,248); border-left-width:3px; border-left-style:solid; border-left-color:rgb(153,153,153)\">\n<a href=\"http:\/\/blog.csdn.net\/v_july_v\/article\/details\/7041827#\" class=\"ViewSource\" title=\"view plain\" style=\"color:rgb(160,160,160); text-decoration:none; background-color:inherit; border:none; padding:0px; margin:0px 10px 0px 0px; font-size:9px\">view plain<\/a><\/div>\n<\/div>\n<ol class=\"dp-cpp\" start=\"1\" style=\"margin:0px 0px 1px 45px!important; padding:0px; border:none; list-style-position:initial; background-color:rgb(255,255,255); color:rgb(92,92,92)\">\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/copyright@&nbsp;saturnman<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/updated@&nbsp;2011&nbsp;July<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"preprocessor\" style=\"margin:0px; padding:0px; border:none; color:gray; background-color:inherit\">#include&nbsp;&quot;stdafx.h&quot;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"preprocessor\" style=\"margin:0px; padding:0px; border:none; color:gray; background-color:inherit\">#include&lt;iostream&gt;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"preprocessor\" style=\"margin:0px; padding:0px; border:none; color:gray; background-color:inherit\">#include&lt;string&gt;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"preprocessor\" style=\"margin:0px; padding:0px; border:none; color:gray; background-color:inherit\">#include&nbsp;&lt;vector&gt;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">using<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">namespace<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;std;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;kmp_find(<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">const<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;string&amp;&nbsp;target,<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">const<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;string&amp;&nbsp;pattern)&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">{&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">const<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;target_length=target.size();&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">const<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;pattern_length=pattern.size();&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">*&nbsp;overlay_value=<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">new<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">[pattern_length];&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;overlay_value[0]=-1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/remember:next&nbsp;array's&nbsp;first&nbsp;number&nbsp;was&nbsp;-1.<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;index=0;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/next&nbsp;array<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">for<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;(<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;i=1;i&lt;pattern_length;&#43;&#43;i)&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u6ce8\uff0c\u6b64\u5904\u7684i\u662f\u4ece1\u5f00\u59cb\u7684<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;index=overlay_value[i-1];&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">while<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;(index&gt;=0&nbsp;&amp;&amp;&nbsp;pattern[index&#43;1]!=pattern[i])&nbsp;&nbsp;<\/span><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/remember:!=<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;index=overlay_value[index];&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">if<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">(pattern[index&#43;1]&nbsp;==&nbsp;pattern[i])&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;overlay_value[i]=index&#43;1;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">else<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;overlay_value[i]=-1;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/mach&nbsp;algorithm&nbsp;start<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;pattern_index=0;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;target_index=0;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">while<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;(pattern_index&lt;pattern_length&nbsp;&amp;&amp;&nbsp;target_index&lt;target_length)&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">if<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;(target[target_index]&nbsp;==&nbsp;pattern[pattern_index])&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#43;&#43;target_index;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#43;&#43;pattern_index;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">else<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">if<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">(pattern_index==0)&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#43;&#43;target_index;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">else<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pattern_index=overlay_value[pattern_index-1]&#43;1;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">if<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;(pattern_index==pattern_length)&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">return<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;target_index-pattern_index;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">else<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">return<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;-1;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">delete<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;[]&nbsp;overlay_value;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">}&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;main()&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">{&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;string&nbsp;sourc=<span class=\"string\" style=\"margin:0px; padding:0px; border:none; color:red; background-color:inherit\">&quot;ababc&quot;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;string&nbsp;pattern=<span class=\"string\" style=\"margin:0px; padding:0px; border:none; color:red; background-color:inherit\">&quot;abc&quot;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;kmp_find(sourc,pattern)&lt;&lt;endl;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;system(<span class=\"string\" style=\"margin:0px; padding:0px; border:none; color:red; background-color:inherit\">&quot;pause&quot;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">);&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">return<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;0;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">}&nbsp;&nbsp;<\/span><\/li>\n<\/ol>\n<\/div>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; \u7531\u4e8e\u662fabc\u8ddfababc\u5339\u914d\uff0c\u90a3\u4e48\u5c06\u8fd4\u56de\u5339\u914d\u7684\u4f4d\u7f6e\u201c2\u201d\uff0c\u8fd0\u884c\u7ed3\u679c\u5982\u6240\u793a\uff1a<\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<img decoding=\"async\" alt=\"\" src=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/0_1323418497xll5.gif\" style=\"border:none\" \/><\/p>\n<h3 style=\"margin:0px; padding:0px; color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left\">\n<a name=\"t4\" style=\"color:rgb(51,102,153)\"><\/a>\u7b2c\u56db\u90e8\u5206\u3001\u6d4b\u8bd5<\/h3>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; \u9488\u5bf9\u4e0a\u6587\u4e2d\u7b2c\u4e09\u90e8\u5206\u7684\u4e24\u6bb5\u4ee3\u7801\u6d4b\u8bd5\u4e86\u4e0b\uff0c\u7ea0\u7ed3\u4e86\uff0c\u4e24\u79cd\u6c42next\u6570\u7ec4\u7684\u65b9\u6cd5\u5bf9\u540c\u4e00\u4e2a\u5b57\u7b26\u4e32\u6c42next\u6570\u7ec4\u5404&#20540;\uff0c\u5f97\u5230\u7684\u7ed3\u679c\u7adf\u7136\u4e0d\u4e00\u6837\uff0c\u5982\u4e0b\u4e8c\u56fe\u6240\u793a\uff1a<\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; 1\u3001\u4e24\u79cd\u65b9\u6cd5\u5bf9\u5b57\u7b26\u4e32<strong>abab<\/strong>\u6c42next\u6570\u7ec4\u5404&#20540;\u6bd4\u8f83\uff1a<img decoding=\"async\" alt=\"\" src=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/0_1323415780EZsh.gif\" style=\"border:none\" \/><\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; 2\u3001\u4e24\u79cd\u5bf9\u5b57\u7b26\u4e32<strong>abaabcaba<\/strong>\u6c42next\u6570\u7ec4\u5404&#20540;\u6bd4\u8f83\uff1a<img decoding=\"async\" alt=\"\" src=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/0_1323414665F40E.gif\" style=\"border:none\" \/><\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; \u4e3a\u4f55\u4f1a\u8fd9\u6837\u5462\uff0c\u5176\u5b9e\u5f88\u7b80\u5355\uff0c\u4e0a\u6587\u4e2d\u5df2\u7ecf\u6709\u6240\u8bf4\u660e\u4e86\uff0c<span style=\"color:rgb(153,0,0)\">\u4ee3\u7801\u5b9e\u73b0\u4e00\u7684i \u662f\u4ece0\u5f00\u59cb\u7684\uff0c\u4ee3\u7801\u5b9e\u73b0\u4e8c\u7684i \u662f\u4ece1\u5f00\u59cb\u7684<\/span>\u3002\u4f46\u4ece\u6700\u7ec8\u7684\u8fd0\u884c\u7ed3\u679c\u6765\u770b\uff0c\u6682\u65f6\u8fd8\u662f\u4ee5\u4ee3\u7801\u5b9e\u73b0\u6bb5\u4e8c\u4e3a\u51c6\u3002<\/p>\n<h3 style=\"margin:0px; padding:0px; color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left\">\n<a name=\"t5\" style=\"color:rgb(51,102,153)\"><\/a>\u7b2c\u4e94\u90e8\u5206\u3001KMP\u5b8c\u6574\u51c6\u786e\u6e90\u7801<\/h3>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; \u6c42next\u6570\u7ec4\u5404&#20540;\u7684\u65b9\u6cd5\u4e3a\uff1a<\/p>\n<div class=\"dp-highlighter bg_cpp\" style=\"font-family:Consolas,'Courier New',Courier,mono,serif; background-color:rgb(231,229,220); width:687px; overflow:auto; margin:18px 0px!important; padding-top:1px; color:rgb(51,51,51); line-height:26px; text-align:left\">\n<div class=\"bar\" style=\"padding-left:45px\">\n<div class=\"tools\" style=\"padding:3px 8px 10px 10px; font-size:9px; line-height:normal; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; color:silver; background-color:rgb(248,248,248); border-left-width:3px; border-left-style:solid; border-left-color:rgb(153,153,153)\">\n<a href=\"http:\/\/blog.csdn.net\/v_july_v\/article\/details\/7041827#\" class=\"ViewSource\" title=\"view plain\" style=\"color:rgb(160,160,160); text-decoration:none; background-color:inherit; border:none; padding:0px; margin:0px 10px 0px 0px; font-size:9px\">view plain<\/a><\/div>\n<\/div>\n<ol class=\"dp-cpp\" start=\"1\" style=\"margin:0px 0px 1px 45px!important; padding:0px; border:none; list-style-position:initial; background-color:rgb(255,255,255); color:rgb(92,92,92)\">\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/copyright@&nbsp;staurman<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/updated@2011&nbsp;July<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"preprocessor\" style=\"margin:0px; padding:0px; border:none; color:gray; background-color:inherit\">#include&nbsp;&quot;StdAfx.h&quot;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"preprocessor\" style=\"margin:0px; padding:0px; border:none; color:gray; background-color:inherit\">#include&lt;iostream&gt;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"preprocessor\" style=\"margin:0px; padding:0px; border:none; color:gray; background-color:inherit\">#include&lt;string&gt;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">using<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">namespace<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;std;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/solve&nbsp;to&nbsp;the&nbsp;next&nbsp;array<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">void<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;compute_overlay(<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">const<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;string&amp;&nbsp;pattern)&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">{&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">const<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;pattern_length&nbsp;=&nbsp;pattern.size();&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;*overlay_function&nbsp;=&nbsp;<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">new<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">[pattern_length];&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;index;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;overlay_function[0]&nbsp;=&nbsp;-1;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">for<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">(<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;i=1;i&lt;pattern_length;&#43;&#43;i)&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;index&nbsp;=&nbsp;overlay_function[i-1];&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/store&nbsp;previous&nbsp;fail&nbsp;position&nbsp;k&nbsp;to&nbsp;index;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">while<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">(index&gt;=0&nbsp;&amp;&amp;&nbsp;pattern[i]!=pattern[index&#43;1])&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;index&nbsp;=&nbsp;overlay_function[index];&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">if<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">(pattern[i]==pattern[index&#43;1])&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;overlay_function[i]&nbsp;=&nbsp;index&nbsp;&#43;&nbsp;1;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">else<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;overlay_function[i]&nbsp;=&nbsp;-1;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">for<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">(<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;i=0;i&lt;pattern_length;&#43;&#43;i)&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;overlay_function[i]&lt;&lt;endl;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">delete<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">[]&nbsp;overlay_function;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">}&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/abaabcaba<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;main()&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">{&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;string&nbsp;pattern&nbsp;=&nbsp;<span class=\"string\" style=\"margin:0px; padding:0px; border:none; color:red; background-color:inherit\">&quot;abaabcaba&quot;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;compute_overlay(pattern);&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;system(<span class=\"string\" style=\"margin:0px; padding:0px; border:none; color:red; background-color:inherit\">&quot;pause&quot;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">);&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">return<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;0;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">}&nbsp;&nbsp;<\/span><\/li>\n<\/ol>\n<\/div>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; \u8fd0\u884c\u7ed3\u679c\u5165\u4e0b\u56fe\u6240\u793a\uff1a<span style=\"font-size:24px\">abab\u7684next\u6570\u7ec4\u5404&#20540;\u662f-1\uff0c-1,0,1\uff0c\u800c\u975e\u672c\u6587\u7b2c\u4e8c\u90e8\u5206\u6240\u8ff0\u7684-1,0\uff0c-1,0<\/span>\u3002\u4e3a\u4ec0\u4e48\u5462\uff1f\u96be\u9053\u662f\u642c\u77f3\u5934\u7838\u4e86\u81ea\u5df1\u7684\u811a\uff1f<\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; NO\uff0c\u4e0a\u6587\u7b2c\u56db\u90e8\u5206\u672b\u5df2\u7ecf\u8be6\u7ec6\u8bf4\u660e\uff0c\u4e0a\u5904\u4ee3\u7801i \u4ece0\u5f00\u59cb\uff0c\u672c\u6587\u7b2c\u4e8c\u90e8\u5206\u4ee3\u7801i \u4ece1\u5f00\u59cb\u3002<\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<img decoding=\"async\" alt=\"\" src=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/0_13234174252zC2.gif\" style=\"border:none\" \/><\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; KMP\u7b97\u6cd5\u5b8c\u6574\u6e90\u7801\uff0c\u5982\u4e0b\uff1a<\/p>\n<div class=\"dp-highlighter bg_cpp\" style=\"font-family:Consolas,'Courier New',Courier,mono,serif; background-color:rgb(231,229,220); width:687px; overflow:auto; margin:18px 0px!important; padding-top:1px; color:rgb(51,51,51); line-height:26px; text-align:left\">\n<div class=\"bar\" style=\"padding-left:45px\">\n<div class=\"tools\" style=\"padding:3px 8px 10px 10px; font-size:9px; line-height:normal; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; color:silver; background-color:rgb(248,248,248); border-left-width:3px; border-left-style:solid; border-left-color:rgb(153,153,153)\">\n<a href=\"http:\/\/blog.csdn.net\/v_july_v\/article\/details\/7041827#\" class=\"ViewSource\" title=\"view plain\" style=\"color:rgb(160,160,160); text-decoration:none; background-color:inherit; border:none; padding:0px; margin:0px 10px 0px 0px; font-size:9px\">view plain<\/a><\/div>\n<\/div>\n<ol class=\"dp-cpp\" start=\"1\" style=\"margin:0px 0px 1px 45px!important; padding:0px; border:none; list-style-position:initial; background-color:rgb(255,255,255); color:rgb(92,92,92)\">\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/copyright@&nbsp;saturnman<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/updated@&nbsp;2011&nbsp;July<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"preprocessor\" style=\"margin:0px; padding:0px; border:none; color:gray; background-color:inherit\">#include&nbsp;&quot;stdafx.h&quot;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"preprocessor\" style=\"margin:0px; padding:0px; border:none; color:gray; background-color:inherit\">#include&lt;iostream&gt;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"preprocessor\" style=\"margin:0px; padding:0px; border:none; color:gray; background-color:inherit\">#include&lt;string&gt;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"preprocessor\" style=\"margin:0px; padding:0px; border:none; color:gray; background-color:inherit\">#include&nbsp;&lt;vector&gt;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">using<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">namespace<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;std;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;kmp_find(<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">const<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;string&amp;&nbsp;target,<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">const<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;string&amp;&nbsp;pattern)&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">{&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">const<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;target_length=target.size();&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">const<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;pattern_length=pattern.size();&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">*&nbsp;overlay_value=<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">new<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">[pattern_length];&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;overlay_value[0]=-1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/remember:next&nbsp;array's&nbsp;first&nbsp;number&nbsp;was&nbsp;-1.<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;index=0;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/next&nbsp;array<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">for<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;(<\/span><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;i=1;i&lt;pattern_length;&#43;&#43;i)&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/\u6ce8\uff0c\u6b64\u5904\u7684i\u662f\u4ece1\u5f00\u59cb\u7684<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;index=overlay_value[i-1];&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">while<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;(index&gt;=0&nbsp;&amp;&amp;&nbsp;pattern[index&#43;1]!=pattern[i])&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;index=overlay_value[index];&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">if<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">(pattern[index&#43;1]&nbsp;==&nbsp;pattern[i])&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;overlay_value[i]=index&#43;1;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">else<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;overlay_value[i]=-1;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"comment\" style=\"margin:0px; padding:0px; border:none; color:rgb(0,130,0); background-color:inherit\">\/\/mach&nbsp;algorithm&nbsp;start<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;pattern_index=0;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;target_index=0;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">while<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;(pattern_index&lt;pattern_length&nbsp;&amp;&amp;&nbsp;target_index&lt;target_length)&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">if<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;(target[target_index]&nbsp;==&nbsp;pattern[pattern_index])&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#43;&#43;target_index;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#43;&#43;pattern_index;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">else<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;<\/span><span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">if<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">(pattern_index==0)&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#43;&#43;target_index;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">else<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pattern_index=overlay_value[pattern_index-1]&#43;1;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">if<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;(pattern_index==pattern_length)&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">return<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;target_index-pattern_index;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">else<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">return<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;-1;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">delete<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;[]&nbsp;overlay_value;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">}&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\"><span class=\"datatypes\" style=\"margin:0px; padding:0px; border:none; color:rgb(46,139,87); background-color:inherit; font-weight:bold\">int<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;main()&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">{&nbsp;&nbsp;<\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;string&nbsp;sourc=<span class=\"string\" style=\"margin:0px; padding:0px; border:none; color:red; background-color:inherit\">&quot;ababc&quot;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;string&nbsp;pattern=<span class=\"string\" style=\"margin:0px; padding:0px; border:none; color:red; background-color:inherit\">&quot;abc&quot;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;kmp_find(sourc,pattern)&lt;&lt;endl;&nbsp;&nbsp;<\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;system(<span class=\"string\" style=\"margin:0px; padding:0px; border:none; color:red; background-color:inherit\">&quot;pause&quot;<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">);&nbsp;&nbsp;<\/span><\/span><\/li>\n<li style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:rgb(85,85,85); line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"keyword\" style=\"margin:0px; padding:0px; border:none; color:blue; background-color:inherit; font-weight:bold\">return<\/span><span style=\"margin:0px; padding:0px; border:none; background-color:inherit\">&nbsp;0;&nbsp;&nbsp;<\/span><\/span><\/li>\n<li class=\"alt\" style=\"margin:0px!important; padding:0px 3px 0px 10px!important; border-style:none none none solid; border-left-width:3px; border-left-color:rgb(153,153,153); list-style:decimal-leading-zero outside; background-color:rgb(245,250,226); color:inherit; line-height:18px\">\n<span style=\"margin:0px; padding:0px; border:none; color:black; background-color:inherit\">}&nbsp;&nbsp;<\/span><\/li>\n<\/ol>\n<\/div>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<strong>&nbsp;&nbsp;&nbsp;&nbsp;<\/strong>\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<img decoding=\"async\" alt=\"\" src=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/0_13234207304Rm0.gif\" style=\"border:none\" \/><\/p>\n<h3 style=\"margin:0px; padding:0px; color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left\">\n<a name=\"t6\" style=\"color:rgb(51,102,153)\"><\/a>\u7b2c\u516d\u90e8\u5206\u3001\u4e00&#30524;\u770b\u51fa\u5b57\u7b26\u4e32\u7684next\u6570\u7ec4\u5404&#20540;<\/h3>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; \u4e0a\u6587\u5df2\u7ecf\u7528\u7a0b\u5e8f\u6c42\u51fa\u4e86\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684next\u6570\u7ec4\u5404&#20540;\uff0c\u63a5\u4e0b\u6765\uff0c\u7a0d\u7a0d\u6f14\u793a\u4e0b\uff0c\u5982\u4f55\u4e00&#30524;\u5927\u81f4\u5224\u65ad\u51fanext\u6570\u7ec4\u5404&#20540;\uff0c\u4ee5\u53ca\u521d\u6b65\u5224\u65ad\u67d0\u4e2a\u7a0b\u5e8f\u6c42\u51fa\u7684next\u6570\u7ec4\u5404&#20540;\u662f\u4e0d\u662f\u6b63\u786e\u7684\u3002\u6709\u4e00\u70b9\u52a1\u5fc5\u6ce8\u610f\uff1a<span style=\"color:rgb(153,0,0)\">\u4e0b\u6587\u4e2d\u7684\u4ee3\u7801\u5168\u90e8\u91c7\u53d6\u4ee3\u7801\u5b9e\u73b0\u4e8c\uff0c\u5373i\u662f\u4ece1\u5f00\u59cb\u7684<\/span>\u3002<\/p>\n<ul style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<li>1\u3001\u5bf9\u5b57\u7b26\u4e32aba\u6c42next\u6570\u7ec4\u5404&#20540;\uff0c\u5404\u4f4d\u53ef\u4ee5\u5148\u731c\u731c\uff0c-1\uff0c...\uff0caba\u4e2d\uff0ca\u521d\u59cb\u5316\u4e3a-1\uff0c\u7b2c\u4e8c\u4e2a\u5b57\u7b26b\u4e0ea\u4e0d\u540c\u4e5f\u4e3a-1\uff0c\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u548c\u7b2c\u4e00\u4e2a\u5b57\u7b26\u90fd\u662fa\uff0c\u6240\u4ee5\uff0c\u6211\u731c\u5176next\u6570\u7ec4\u5404&#20540;\u5e94\u8be5\u662f-1\uff0c-1,0\uff0c\u7ed3\u679c\u4e5f\u4e0d\u51fa\u6240\u6599\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/li>\n<\/ul>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<img decoding=\"async\" alt=\"\" src=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/0_1323421403lIU8.gif\" style=\"border:none\" \/><\/p>\n<ul style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<li>2\u3001\u5b57\u7b26\u4e32\u201cabab\u201d\u5462\uff0c\u4e0d\u7528\u731c\u4e86\uff0c\u6211\u5df2\u7ecf\u770b\u51fa\u6765\u4e86\uff0c\u5f53\u7136\u4e0a\u6587\u4e2d\u4ee3\u7801\u5b9e\u73b0\u4e00\u548c\u4ee3\u7801\u5b9e\u73b0\u4e8c\u90fd\u5df2\u7ecf\u6c42\u51fa\u6765\u4e86\u3002\u5982\u679ci \u662f1\u5f00\u59cb\u7684\u8bdd\uff0c\u90a3\u4e48next\u6570\u7ec4\u5404&#20540;\u5c06\u5982\u4ee3\u7801\u5b9e\u73b0\u4e8c\u6240\u8fd0\u884c\u7684\u90a3\u6837\uff0c\u5c06\u662f\uff1a-1\uff0c-1,0,1\uff1b<\/li>\n<li>3\u3001\u5b57\u7b26\u4e32\u201cabaabcaba\u201d\u5462\uff0cnext\u6570\u7ec4\u5982\u4e0a\u7b2c\u4e09\u90e8\u5206\u4ee3\u7801\u5b9e\u73b0\u4e8c\u6240\u8ff0\uff0c\u4e3a-1\uff0c-1,0,0,1\uff0c-1,0,1,2\uff1b<\/li>\n<li>4\u3001\u5b57\u7b26\u4e32\u201cabcdab\u201d\u5462\uff0cnext\u6570\u7ec4\u5404&#20540;\u5c06\u662f-1\uff0c-1\uff0c-1\uff0c-1,0,1\uff1b<\/li>\n<li>5\u3001\u5b57\u7b26\u4e32\u201cabcdabc\u201d\u5462\uff0cnext\u6570\u7ec4\u5404&#20540;\u5c06\u662f-1\uff0c-1\uff0c-1\uff0c-1,0,1,2\uff1b<\/li>\n<li>6\u3001\u5b57\u7b26\u4e32\u201cabcdabcd\u201d\u5462\uff0c\u90a3\u4e48next\u6570\u7ec4\u5404&#20540;\u5c06\u662f-1\uff0c-1\uff0c-1\uff0c-1,0\uff0c1,2,3\uff1b<\/li>\n<\/ul>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<img decoding=\"async\" alt=\"\" src=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/0_13234227806AQ4.gif\" style=\"border:none\" \/><\/p>\n<p style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; \u600e\u4e48\u6837\uff0c\u770b\u51fa\u89c4\u5f8b\u6765\u4e86\u6ca1\uff1f\u5475\u5475\uff0c\u53ef\u4ee5\u7528\u4e0a\u8ff0\u7b2c\u4e94\u90e8\u5206\u4e2d\u6c42next\u6570\u7ec4\u7684\u65b9\u6cd5\u81ea\u4e2a\u591a\u8bd5\u63a2\u51e0\u6b21\uff0c\u76f8\u4fe1\uff0c\u5f88\u5feb\uff0c\u4f60\u4e5f\u4f1a\u8ddf\u6211\u4e00\u6837\uff0c\u4e0d\u7528\u8ba1\u7b97\uff0c\u4e00&#30524;\u4fbf\u80fd\u770b\u51fa\u67d0\u4e2a\u5b57\u7b26\u4e32\u7684next\u6570\u7ec4\u5404&#20540;\u4e86\u3002\u5982\u6b64\u4fbf\u606d\u559c\u4f60\uff0c\u7406\u89e3\u4e86next\u6570\u7ec4\u7684\u6c42\u6cd5\uff0cKMP\u7b97\u6cd5\u4e5f\u5c31\u7b97\u662f\u771f\u771f\u6b63\u6b63\u5f7b\u5f7b\u5e95\u5e95\u7684\u7406\u89e3\u4e86\u3002\u5b8c\u3002<\/p>\n<h3 style=\"margin:0px; padding:0px; color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left\">\n<a name=\"t7\" style=\"color:rgb(51,102,153)\"><\/a>\u76f8\u5173\u94fe\u63a5<\/h3>\n<ol style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<li>KMP\u4e4b\u7b2c\u4e8c\u7bc7\u6587\u7ae0\uff1a<a href=\"http:\/\/blog.csdn.net\/v_JULY_v\/archive\/2011\/06\/15\/6545192.aspx\" target=\"_blank\" style=\"color:rgb(34,0,0); text-decoration:none\" rel=\"noopener\">\u516d\uff08\u7eed\uff09\u3001\u4eceKMP\u7b97\u6cd5\u4e00\u6b65\u4e00\u6b65\u8c08\u5230BM\u7b97\u6cd5<\/a>\u3002<\/li>\n<li>KMP\u4e4b\u7b2c\u4e00\u7bc7\u6587\u7ae0\uff1a<a href=\"http:\/\/blog.csdn.net\/v_JULY_v\/archive\/2011\/01\/01\/6111565.aspx\" target=\"_blank\" style=\"color:rgb(51,102,153); text-decoration:none\" rel=\"noopener\">\u516d\u3001\u6559\u4f60\u521d\u6b65\u4e86\u89e3KMP\u7b97\u6cd5\u3001updated<\/a>\u3002<\/li>\n<\/ol>\n<h3 style=\"margin:0px; padding:0px; color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left\">\n<a name=\"t8\" style=\"color:rgb(51,102,153)\"><\/a>\u540e\u8bb0&nbsp;<\/h3>\n<div style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp; &nbsp; &nbsp;\u76f8\u4fe1\uff0c\u770b\u8fc7\u6b64\u6587\u540e\uff0c\u65e0\u8bba\u662f\u8c01\uff0c\u90fd\u4e00\u5b9a\u53ef\u4ee5\u628aKMP\u7b97\u6cd5\u641e\u61c2\u4e86\uff08\u4f46\u4e07\u4e00\u8fd8\u662f\u6709\u8bfb\u8005\u6ca1\u6709\u641e\u61c2\uff0c\u90a3\u600e\u4e48\u529e\u5462\uff1f\u8fd8\u6709\u6700\u540e\u4e00\u4e2a\u529e\u6cd5\uff1a\u628a\u672c\u6587\u6253\u5370\u4e0b\u6765\uff0c\u518d\u4ed4\u7ec6\u7422\u78e8\u3002\u5982\u679c\u662f\u771f\u771f\u6b63\u6b63\u60f3\u5f7b\u5e95\u5f04\u61c2\u67d0\u4e00\u4e2a\u4e1c\u897f\uff0c\u90a3\u4e48\u5fc5\u987b\u4ed8\u51fa\u4e9b\u4ee3\u4ef7\u3002\u4f46\u4e07\u4e00\u8981\u662f\u6253\u5370\u4e0b\u6765\u4e86\u5374\u8fd8\u662f\u6ca1\u6709\u5f04\u61c2\u5462\uff1f\u90a3\u6765\u5317\u4eac\u627e\u6211\u5427\uff0c\u6211\u624b\u628a\u624b\u6559\u4f60\u3002\u795d\u597d\u8fd0\uff09\u3002<\/div>\n<div style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp; &nbsp; \u5728\u7ed3\u675f\u5168\u6587\u4e4b\u524d\uff0c\u8c08\u4e24\u70b9\u611f\u609f\uff1a<\/div>\n<div style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n<ol>\n<li>\u8bed\u8a00-&gt;\u6570\u636e\u7ed3\u6784-&gt;\u7b97\u6cd5\uff1a\u8bed\u8a00\u662f\u57fa\u7840\uff0c\u591f\u5543\u4e00\u8f88\u5b50\uff0c\u57fa\u672c\u7684\u5e38\u89c1\u7684\u6570\u636e\u7ed3\u6784\u5f97\u4e86\u5982\u6307\u638c\uff0c\u6700\u540e\u624d\u662f\u7b97\u6cd5\u3002\u9664\u4e86\u7b97\u6cd5\u4e4b\u5916\uff0c\u6709\u66f4\u591a\u66f4\u91cd\u8981\u4e14\u66f4&#20540;\u5f97\u5b66\u4e60\u7684\u4e1c\u897f\uff08\u6700\u91cd\u8981\u7684\u662f\uff0c\u5b66\u4e60\u5982\u4f55\u7f16\u7a0b\uff09\u3002\u5207\u52ff\u76f2\u76ee\u8ddf\u98ce\uff0c\u627e\u51c6\u81ea\u5df1\u7684\u5174\u8da3\u70b9\uff0c\u548c\u9886\u57df\u624d\u662f\u5173\u952e\u3002\u8fd9\u8ddf\u9009\u62e9\u804c\u4f4d\u3001\u4e0e\u9886\u57df\u5e76\u6301\u4e45\u505a\u4e0b\u53bb\uff0c\u6bd4\u9009\u62e9\u516c\u53f8\u66f4\u91cd\u8981\u4e00\u6837\u3002\u9009\u62e9\u5b66\u4ec0\u4e48\u4e1c\u897f\u4e0d\u91cd\u8981\uff0c\u91cd\u8981\u7684\u662f\u4f60\u7684\u5174\u8da3\u3002<\/li>\n<li>\u4fee\u8ba2\u8fd9\u7bc7\u6587\u7ae0\u4e4b\u65f6\uff0c\u4e2a\u4eba\u63a5\u89e6KMP\u90fd\u6709\u4e00\u5e74\u4e86\uff0c\u5b66\u7b97\u6cd5\u4e5f\u521a\u597d\u5feb\u4e00\u5e74\u3002\u60f3\u60f3\u963f\uff0c\u6211\u5f04\u4e00\u4e2aKMP\uff0c\u5f04\u4e86\u8fd1\u4e00\u5e74\u4e86\uff0c\u5230\u4eca\u5929\u624d\u7b97\u662f\u771f\u6b63\u5f7b\u5e95\u7406\u89e3\u5176\u601d\u60f3\uff0c\u53ef\u60f3\u800c\u77e5\uff0c\u5f53\u521d\u521b\u9020\u8fd9\u4e2a\u7b97\u6cd5\u7684k\u3001m\u3001p\u4e09\u4eba\u662f\u4f55\u7b49\u4e0d\u6613\u3002\u6211\u60f3\uff0c\u6709\u4e0d\u5c11\u8bfb\u8005\u662f\u56e0\u4e3a\u6211\u7684\u51fa\u73b0\u800c\u60f3\u5b66\u7b97\u6cd5\u7684\uff0c\u4f46\u4e0d\u53ef\u6025\u529f\u8fd1\u5229\uff0c\u5207\u52ff\u5984\u60f3\u7b97\u6cd5\u901f\u6210\u3002\u65e9\u5df2\u8bf4\u8fc7\uff0c\u5b66\u7b97\u6cd5\u5148\u4fee\u5fc3\u3002\n<\/li>\n<\/ol>\n<\/div>\n<div style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp; &nbsp; &nbsp;OK\uff0c\u6587\u4e2d\u6709\u5173\u4efb\u4f55\u95ee\u9898\u6216\u9519\u8bef\uff0c\u70e6\u8bf7\u4e0d\u541d\u8d50\u6559\u4e0e\u6307\u6b63\u3002\u8c22\u8c22\uff0c\u5b8c\u3002<\/div>\n<div style=\"color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px; text-align:left\">\n&nbsp;&nbsp;&nbsp; July\u3001\u4e8c\u96f6\u4e00\u4e00\u5e74\u5341\u4e8c\u6708\u4e94\u65e5\u4e2d\u5348\u3002<\/div>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f5c\u8005\uff1aJuly\u3002 \u51fa\u5904\uff1ahttp:\/\/blog.csdn.net\/v_JULY_v\/\u3002 \u5f15\u8bb0 &nbsp;&#038;n [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","footnotes":""},"categories":[3],"tags":[34],"class_list":["post-255","post","type-post","status-publish","format-standard","hentry","category-defaultcategory","tag-kmp"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>KMP - nike0good<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/nike0good.com\/?p=255\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"KMP - nike0good\" \/>\n<meta property=\"og:description\" content=\"\u4f5c\u8005\uff1aJuly\u3002 \u51fa\u5904\uff1ahttp:\/\/blog.csdn.net\/v_JULY_v\/\u3002 \u5f15\u8bb0 &nbsp;&amp;n [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/nike0good.com\/?p=255\" \/>\n<meta property=\"og:site_name\" content=\"nike0good\" \/>\n<meta property=\"article:published_time\" content=\"2012-11-12T06:01:00+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/other_site\/img_t_newj_org.gif\" \/>\n<meta name=\"author\" content=\"nike0good\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"nike0good\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"32 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=255#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=255\"},\"author\":{\"name\":\"nike0good\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/#\\\/schema\\\/person\\\/4defa38da89de87e400861e73396baad\"},\"headline\":\"KMP\",\"datePublished\":\"2012-11-12T06:01:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=255\"},\"wordCount\":6509,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=255#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/nike0good.jp1.rpvhost.net\\\/wp-content\\\/uploads\\\/csdn\\\/other_site\\\/img_t_newj_org.gif\",\"keywords\":[\"KMP\"],\"articleSection\":[\"DefaultCategory\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/nike0good.com\\\/?p=255#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=255\",\"url\":\"https:\\\/\\\/nike0good.com\\\/?p=255\",\"name\":\"KMP - nike0good\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=255#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=255#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/nike0good.jp1.rpvhost.net\\\/wp-content\\\/uploads\\\/csdn\\\/other_site\\\/img_t_newj_org.gif\",\"datePublished\":\"2012-11-12T06:01:00+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/#\\\/schema\\\/person\\\/4defa38da89de87e400861e73396baad\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=255#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/nike0good.com\\\/?p=255\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=255#primaryimage\",\"url\":\"http:\\\/\\\/nike0good.jp1.rpvhost.net\\\/wp-content\\\/uploads\\\/csdn\\\/other_site\\\/img_t_newj_org.gif\",\"contentUrl\":\"http:\\\/\\\/nike0good.jp1.rpvhost.net\\\/wp-content\\\/uploads\\\/csdn\\\/other_site\\\/img_t_newj_org.gif\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=255#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/nike0good.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"KMP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/#website\",\"url\":\"https:\\\/\\\/nike0good.com\\\/\",\"name\":\"nike0good\",\"description\":\"\u6709\u6240\u4f5c\u4e3a\u662f\u4eba\u751f\u7684\u6700\u9ad8\u5883\u754c\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/nike0good.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/#\\\/schema\\\/person\\\/4defa38da89de87e400861e73396baad\",\"name\":\"nike0good\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g\",\"caption\":\"nike0good\"},\"sameAs\":[\"https:\\\/\\\/nike0good.com\"],\"url\":\"https:\\\/\\\/nike0good.com\\\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"KMP - nike0good","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/nike0good.com\/?p=255","og_locale":"zh_CN","og_type":"article","og_title":"KMP - nike0good","og_description":"\u4f5c\u8005\uff1aJuly\u3002 \u51fa\u5904\uff1ahttp:\/\/blog.csdn.net\/v_JULY_v\/\u3002 \u5f15\u8bb0 &nbsp;&n [&hellip;]","og_url":"https:\/\/nike0good.com\/?p=255","og_site_name":"nike0good","article_published_time":"2012-11-12T06:01:00+00:00","og_image":[{"url":"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/other_site\/img_t_newj_org.gif","type":"","width":"","height":""}],"author":"nike0good","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"nike0good","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"32 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/nike0good.com\/?p=255#article","isPartOf":{"@id":"https:\/\/nike0good.com\/?p=255"},"author":{"name":"nike0good","@id":"https:\/\/nike0good.com\/#\/schema\/person\/4defa38da89de87e400861e73396baad"},"headline":"KMP","datePublished":"2012-11-12T06:01:00+00:00","mainEntityOfPage":{"@id":"https:\/\/nike0good.com\/?p=255"},"wordCount":6509,"commentCount":0,"image":{"@id":"https:\/\/nike0good.com\/?p=255#primaryimage"},"thumbnailUrl":"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/other_site\/img_t_newj_org.gif","keywords":["KMP"],"articleSection":["DefaultCategory"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/nike0good.com\/?p=255#respond"]}]},{"@type":"WebPage","@id":"https:\/\/nike0good.com\/?p=255","url":"https:\/\/nike0good.com\/?p=255","name":"KMP - nike0good","isPartOf":{"@id":"https:\/\/nike0good.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/nike0good.com\/?p=255#primaryimage"},"image":{"@id":"https:\/\/nike0good.com\/?p=255#primaryimage"},"thumbnailUrl":"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/other_site\/img_t_newj_org.gif","datePublished":"2012-11-12T06:01:00+00:00","author":{"@id":"https:\/\/nike0good.com\/#\/schema\/person\/4defa38da89de87e400861e73396baad"},"breadcrumb":{"@id":"https:\/\/nike0good.com\/?p=255#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/nike0good.com\/?p=255"]}]},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/nike0good.com\/?p=255#primaryimage","url":"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/other_site\/img_t_newj_org.gif","contentUrl":"http:\/\/nike0good.jp1.rpvhost.net\/wp-content\/uploads\/csdn\/other_site\/img_t_newj_org.gif"},{"@type":"BreadcrumbList","@id":"https:\/\/nike0good.com\/?p=255#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/nike0good.com\/"},{"@type":"ListItem","position":2,"name":"KMP"}]},{"@type":"WebSite","@id":"https:\/\/nike0good.com\/#website","url":"https:\/\/nike0good.com\/","name":"nike0good","description":"\u6709\u6240\u4f5c\u4e3a\u662f\u4eba\u751f\u7684\u6700\u9ad8\u5883\u754c","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/nike0good.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/nike0good.com\/#\/schema\/person\/4defa38da89de87e400861e73396baad","name":"nike0good","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/secure.gravatar.com\/avatar\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g","caption":"nike0good"},"sameAs":["https:\/\/nike0good.com"],"url":"https:\/\/nike0good.com\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/posts\/255","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nike0good.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=255"}],"version-history":[{"count":0,"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/posts\/255\/revisions"}],"wp:attachment":[{"href":"https:\/\/nike0good.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nike0good.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nike0good.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}