<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> # Simple Match - 簡單匹配 -------- #### 問題 在文本$$ text $$中查找字符串$$ pattern $$出現的所有位置($$ text $$長度為$$ n $$,$$ pattern $$長度為$$ m $$,$$ n, m $$都是正整數且$$ n \gt m $$)。 #### 解法 對于$$ text[0 \dots n] $$,從$$ i = 0, j = 0 $$開始,依次比較$$ text[i+j] = pattern[j] $$。若相等則$$ j $$向后移動一個位置再繼續比較,直到$$ j \ge m $$,即$$ text[i \dots i+m-1] = pattern[0 \dots m-1] $$,說明$$ pattern $$在$$ text $$的$$ i $$下標出現;否則$$ i = i+1, j = 0 $$重新開始新一輪匹配。 下面演示一個匹配的過程: ![SimpleMatch1.svg](../res/SimpleMatch1.svg) $$ (1) $$ 從$$ text $$第$$ 0 $$個字符開始匹配,有$$ text[0 \dots 2] = pattern[0 \dots 2],text[3] \ne pattern[3] $$,繼續匹配下一個字符; ![SimpleMatch2.svg](../res/SimpleMatch2.svg) $$ (2) $$ 從$$ text $$第$$ 1 $$個字符開始匹配,有$$ text[1] \ne pattern[0] $$,繼續匹配下一個字符; $$ \cdots $$ ![SimpleMatch3.svg](../res/SimpleMatch3.svg) $$ (3) $$ 從$$ text $$第$$ 7 $$個字符開始匹配,$$ text[7 \dots 10] = pattern[0 \dots 3] $$,匹配成功,算法結束; 顯然,對于$$ text $$中的每個位置$$ i $$,都需要進行一次匹配,而每次匹配的平均時間復雜度為$$ pattern $$的長度$$ m $$。該算法的時間復雜度為$$ O(m \times n) $$。 -------- #### 源碼 [SimpleMatch.h](https://github.com/linrongbin16/Way-to-Algorithm/blob/master/src/TextMatch/SimpleMatch.h) [SimpleMatch.cpp](https://github.com/linrongbin16/Way-to-Algorithm/blob/master/src/TextMatch/SimpleMatch.cpp) #### 測試 [SimpleMatchTest.cpp](https://github.com/linrongbin16/Way-to-Algorithm/blob/master/src/TextMatch/SimpleMatchTest.cpp)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看