-
Notifications
You must be signed in to change notification settings - Fork 0
/
atom.xml
68 lines (48 loc) · 11.1 KB
/
atom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Positlive的Blog</title>
<subtitle>积极生活</subtitle>
<link href="/atom.xml" rel="self"/>
<link href="http://hanchunyu.cn/"/>
<updated>2017-08-08T19:00:10.000Z</updated>
<id>http://hanchunyu.cn/</id>
<author>
<name>hcy</name>
<email>[email protected]</email>
</author>
<generator uri="http://hexo.io/">Hexo</generator>
<entry>
<title>kmp</title>
<link href="http://hanchunyu.cn/2017/08/09/kmp/"/>
<id>http://hanchunyu.cn/2017/08/09/kmp/</id>
<published>2017-08-08T17:50:56.000Z</published>
<updated>2017-08-08T19:00:10.000Z</updated>
<content type="html"><![CDATA[<p>KMP算法是一种改进的字符串匹配算法,由D.E.Knuth,J.H.Morris和V.R.Pratt同时发现,因此人们称它为克努特——莫里斯——普拉特操作(简称KMP算法)。KMP算法的关键是利用匹配失败后的信息,尽量减少模式串与主串的匹配次数以达到快速匹配的目的。具体实现就是实现一个next()函数,函数本身包含了模式串的局部匹配信息。时间复杂度O(m+n)。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div></pre></td><td class="code"><pre><div class="line">//</div><div class="line">// kmp.c</div><div class="line">// </div><div class="line">//</div><div class="line">// Created by LiveMac on 2017/8/8.</div><div class="line">//</div><div class="line">//</div><div class="line">#include <stdio.h></div><div class="line">#include <string.h></div><div class="line"></div><div class="line">void get_next(char* T, int* next)</div><div class="line">{</div><div class="line"> int i = 1;</div><div class="line"> int j = 0;</div><div class="line"> next[1] = 0;</div><div class="line"> while (i < T[0])</div><div class="line"> {</div><div class="line"> if (j == 0 || T[i] == T[j])</div><div class="line"> {</div><div class="line"> i++;</div><div class="line"> j++;</div><div class="line"> if (T[i] != T[j])</div><div class="line"> {</div><div class="line"> next[i] = j;</div><div class="line"> }</div><div class="line"> else</div><div class="line"> {</div><div class="line"> next[i] = next[j];</div><div class="line"> }</div><div class="line"> }</div><div class="line"> else</div><div class="line"> {</div><div class="line"> j = next[j];</div><div class="line"> }</div><div class="line"> }</div><div class="line">}</div><div class="line"></div><div class="line">int index_kmp(char* S, char* T, int pos)</div><div class="line">{</div><div class="line"> int i = pos;</div><div class="line"> int j = 1;</div><div class="line"> int next[255];</div><div class="line"> get_next(T, next);</div><div class="line"> while(i <= S[0] && j <= T[0])</div><div class="line"> {</div><div class="line"> if (j == 0 || S[i] == T[j])</div><div class="line"> {</div><div class="line"> i++;</div><div class="line"> j++;</div><div class="line"> }</div><div class="line"> else</div><div class="line"> {</div><div class="line"> j = next[j];</div><div class="line"> }</div><div class="line"> }</div><div class="line"> if (j > T[0])</div><div class="line"> {</div><div class="line"> return i - T[0];</div><div class="line"> }</div><div class="line"> else {</div><div class="line"> return 0;</div><div class="line"> }</div><div class="line">}</div><div class="line"></div><div class="line">int main()</div><div class="line">{</div><div class="line"> char S[255] = " aasssbbsdfdsfas";</div><div class="line"> S[0] = strlen(S) - 1;</div><div class="line"> char T[255] = " sssb";</div><div class="line"> char Input[255];</div><div class="line"> int pos = 1;</div><div class="line"> printf("check[%s][%d], please input substr:\n", S, S[0]);</div><div class="line"> while(1)</div><div class="line"> {</div><div class="line"> scanf("%s",Input);</div><div class="line"> int i = 0;</div><div class="line"> while(Input[i] != '\0')</div><div class="line"> {</div><div class="line"> T[i+1] = Input[i];</div><div class="line"> i++;</div><div class="line"> }</div><div class="line"> T[i+1] = '\0';</div><div class="line"> T[0] = strlen(T) - 1;</div><div class="line"> printf("Input[%s][%lu] -> T[%s][%lu][%d]\n", Input, strlen(Input), T, strlen(T), T[0]);</div><div class="line"> int ret = index_kmp(S, T, pos);</div><div class="line"> if (ret)</div><div class="line"> {</div><div class="line"> printf("[%s] has substr [%s] in pos [%d]\n\n", S, T, ret);</div><div class="line"> }</div><div class="line"> else</div><div class="line"> {</div><div class="line"> printf("[%s] no substr [%s]\n\n", S, T);</div><div class="line"> }</div><div class="line"> }</div><div class="line">}</div></pre></td></tr></table></figure></p>
]]></content>
<summary type="html">
<p>KMP算法是一种改进的字符串匹配算法,由D.E.Knuth,J.H.Morris和V.R.Pratt同时发现,因此人们称它为克努特——莫里斯——普拉特操作(简称KMP算法)。KMP算法的关键是利用匹配失败后的信息,尽量减少模式串与主串的匹配次数以达到快速匹配的目的。具体实现
</summary>
<category term="算法" scheme="http://hanchunyu.cn/tags/%E7%AE%97%E6%B3%95/"/>
<category term="字符串" scheme="http://hanchunyu.cn/tags/%E5%AD%97%E7%AC%A6%E4%B8%B2/"/>
</entry>
<entry>
<title>Hello World</title>
<link href="http://hanchunyu.cn/2017/08/09/hello-world/"/>
<id>http://hanchunyu.cn/2017/08/09/hello-world/</id>
<published>2017-08-08T17:32:59.000Z</published>
<updated>2017-08-08T17:32:59.000Z</updated>
<content type="html"><![CDATA[<p>Welcome to <a href="https://hexo.io/" target="_blank" rel="external">Hexo</a>! This is your very first post. Check <a href="https://hexo.io/docs/" target="_blank" rel="external">documentation</a> for more info. If you get any problems when using Hexo, you can find the answer in <a href="https://hexo.io/docs/troubleshooting.html" target="_blank" rel="external">troubleshooting</a> or you can ask me on <a href="https://github.com/hexojs/hexo/issues" target="_blank" rel="external">GitHub</a>.</p>
<h2 id="Quick-Start"><a href="#Quick-Start" class="headerlink" title="Quick Start"></a>Quick Start</h2><h3 id="Create-a-new-post"><a href="#Create-a-new-post" class="headerlink" title="Create a new post"></a>Create a new post</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ hexo new <span class="string">"My New Post"</span></div></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/writing.html" target="_blank" rel="external">Writing</a></p>
<h3 id="Run-server"><a href="#Run-server" class="headerlink" title="Run server"></a>Run server</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ hexo server</div></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/server.html" target="_blank" rel="external">Server</a></p>
<h3 id="Generate-static-files"><a href="#Generate-static-files" class="headerlink" title="Generate static files"></a>Generate static files</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ hexo generate</div></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/generating.html" target="_blank" rel="external">Generating</a></p>
<h3 id="Deploy-to-remote-sites"><a href="#Deploy-to-remote-sites" class="headerlink" title="Deploy to remote sites"></a>Deploy to remote sites</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ hexo deploy</div></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/deployment.html" target="_blank" rel="external">Deployment</a></p>
]]></content>
<summary type="html">
<p>Welcome to <a href="https://hexo.io/" target="_blank" rel="external">Hexo</a>! This is your very first post. Check <a href="https://hexo.
</summary>
</entry>
</feed>