﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-HelloWorld 善战者,求之于势,不责于人;故能择人而任势。-随笔分类-数据结构和算法</title><link>http://www.blogjava.net/zhaochengming/category/38515.html</link><description> 知止而后有定，定而后能静，静而后能安，安而后能虑，虑而后能得。物有本末，事有终始。知所先后，则近道矣。</description><language>zh-cn</language><lastBuildDate>Mon, 22 Mar 2010 14:19:45 GMT</lastBuildDate><pubDate>Mon, 22 Mar 2010 14:19:45 GMT</pubDate><ttl>60</ttl><item><title>(#BYYL-3-99) NFA构造DFA的子集算法</title><link>http://www.blogjava.net/zhaochengming/archive/2010/03/21/316084.html</link><dc:creator>helloworld2008</dc:creator><author>helloworld2008</author><pubDate>Sun, 21 Mar 2010 08:17:00 GMT</pubDate><guid>http://www.blogjava.net/zhaochengming/archive/2010/03/21/316084.html</guid><wfw:comment>http://www.blogjava.net/zhaochengming/comments/316084.html</wfw:comment><comments>http://www.blogjava.net/zhaochengming/archive/2010/03/21/316084.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zhaochengming/comments/commentRss/316084.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zhaochengming/services/trackbacks/316084.html</trackback:ping><description><![CDATA[<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><font  face="宋体" size="6"><span  style="font-size: 21px;"><strong>
<div class="Section0" style="layout-grid:15.6000pt;">
<p class="p0" style="margin-bottom:0pt; margin-top:0pt; text-align:center; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:16.0000pt; font-family:'宋体'; ">NFA<font face="宋体">构造DFA的子集算法</font></span><span style="mso-spacerun:'yes'; font-weight:bold; font-size:16.0000pt; font-family:'宋体'; "><o:p></o:p></span></p>
<p class="p0" style="margin-left:0.0500pt; text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:14.0000pt; font-family:'Wingdings'; ">n&nbsp;</span><span style="mso-spacerun:'yes'; font-weight:bold; font-size:14.0000pt; font-family:'宋体'; ">输入：一个NFA&nbsp;</span><span style="mso-spacerun:'yes'; color:rgb(0,0,255); font-weight:bold; font-size:14.0000pt; font-family:'宋体'; ">N</span><span style="mso-spacerun:'yes'; font-weight:bold; font-size:14.0000pt; font-family:'宋体'; "><o:p></o:p></span></p>
<p class="p0" style="margin-left:0.0500pt; text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:14.0000pt; font-family:'Wingdings'; ">n&nbsp;</span><span style="mso-spacerun:'yes'; font-weight:bold; font-size:14.0000pt; font-family:'宋体'; ">输出：一个DFA&nbsp;</span><span style="mso-spacerun:'yes'; color:rgb(0,0,255); font-weight:bold; font-size:14.0000pt; font-family:'宋体'; ">D</span><span style="mso-spacerun:'yes'; font-weight:bold; font-size:14.0000pt; font-family:'宋体'; "><o:p></o:p></span></p>
<p class="p0" style="margin-left:0.0500pt; text-indent:21.0000pt; margin-bottom:0pt; margin-top:0pt; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:14.0000pt; font-family:'Wingdings'; ">n&nbsp;</span><span style="mso-spacerun:'yes'; font-weight:bold; font-size:14.0000pt; font-family:'宋体'; ">方法：为D构造一个转换表Dtran。D的每一个状态是一组NFA状态的集合。以下是一些构造需要用到的函数。</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
<table style="border-collapse: collapse; ">
    <tbody>
        <tr>
            <td width="190" valign="top" style="width: 142.6pt; padding-top: 0pt; padding-right: 5.4pt; padding-bottom: 0pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffff99; background-position: initial initial; background-repeat: initial initial; ">
            <p class="p0" style="margin-bottom:0pt; margin-top:0pt; text-align:center; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; "><font face="宋体">操作</font></span><span style="font-weight:bold; font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            </td>
            <td width="378" valign="top" style="width: 283.5pt; padding-top: 0pt; padding-right: 5.4pt; padding-bottom: 0pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffff99; background-position: initial initial; background-repeat: initial initial; ">
            <p class="p0" style="margin-bottom:0pt; margin-top:0pt; text-align:center; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:10.5000pt; font-family:'宋体'; "><font face="宋体">描述</font></span><span style="font-weight:bold; font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            </td>
        </tr>
        <tr>
            <td width="190" valign="top" style="width: 142.6pt; padding-top: 0pt; padding-right: 5.4pt; padding-bottom: 0pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #99cc00; background-position: initial initial; background-repeat: initial initial; ">
            <p class="p0" style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="font-weight:bold; font-size:14.0000pt; font-family:'宋体'; ">&#949;</span><span style="mso-spacerun:'yes'; font-weight:bold; font-size:14.0000pt; font-family:'宋体'; ">-closure(s)</span><span style="font-weight:bold; font-size:14.0000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            </td>
            <td width="378" valign="top" style="width: 283.5pt; padding-top: 0pt; padding-right: 5.4pt; padding-bottom: 0pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #99cc00; background-position: initial initial; background-repeat: initial initial; ">
            <p class="p0" style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; "><font face="宋体">能够从NFA的状态s开始只通过</font></span><span style="font-weight:normal; font-size:10.5000pt; font-family:'宋体'; ">&#949;</span><span style="mso-spacerun:'yes'; font-weight:normal; font-size:10.5000pt; font-family:'宋体'; ">转换到达的NFA状态集合</span><span style="font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            </td>
        </tr>
        <tr>
            <td width="190" valign="top" style="width: 142.6pt; padding-top: 0pt; padding-right: 5.4pt; padding-bottom: 0pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ff99cc; background-position: initial initial; background-repeat: initial initial; ">
            <p class="p0" style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="font-weight:bold; font-size:14.0000pt; font-family:'宋体'; ">&#949;</span><span style="mso-spacerun:'yes'; font-weight:bold; font-size:14.0000pt; font-family:'宋体'; ">-closure(T)</span><span style="font-weight:bold; font-size:14.0000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            </td>
            <td width="378" valign="top" style="width: 283.5pt; padding-top: 0pt; padding-right: 5.4pt; padding-bottom: 0pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ff99cc; background-position: initial initial; background-repeat: initial initial; ">
            <p class="p0" style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="color:rgb(128,0,0); font-size:22.0000pt; font-family:'宋体'; ">U</span><span style="mso-spacerun:'yes'; color:rgb(0,51,0); font-size:22.0000pt; font-family:'宋体'; vertical-align:sub; ">sє</span><span style="color:rgb(0,51,0); font-size:15.0000pt; font-family:'宋体'; vertical-align:sub; ">T</span><span style="mso-spacerun:'yes'; color:rgb(0,0,255); font-weight:bold; font-size:22.0000pt; font-family:'宋体'; ">&#949;-closure(s)</span><span style="font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            </td>
        </tr>
        <tr>
            <td width="190" valign="top" style="width: 142.6pt; padding-top: 0pt; padding-right: 5.4pt; padding-bottom: 0pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffcc00; background-position: initial initial; background-repeat: initial initial; ">
            <p class="p0" style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; font-weight:bold; font-size:14.0000pt; font-family:'宋体'; ">move(T,a)</span><span style="font-weight:bold; font-size:14.0000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            </td>
            <td width="378" valign="top" style="width: 283.5pt; padding-top: 0pt; padding-right: 5.4pt; padding-bottom: 0pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffcc00; background-position: initial initial; background-repeat: initial initial; ">
            <p class="p0" style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; "><font face="宋体">能够从T中某个状态S出发通过标号为a的转换到达的NFA状态的集合</font></span><span style="font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            </td>
        </tr>
    </tbody>
</table>
<p class="p0" style="margin-left:21.0500pt; margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; color:rgb(0,0,128); font-weight:bold; font-size:14.0000pt; font-family:'Wingdings'; ">&#216;&nbsp;</span><span style="mso-spacerun:'yes'; color:rgb(0,0,128); font-weight:bold; font-size:14.0000pt; font-family:'宋体'; ">构造D的状态集合DStates和D的转换函数Dtran</span><span style="mso-spacerun:'yes'; color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
<table style="border-collapse: collapse; ">
    <tbody>
        <tr>
            <td width="568" valign="top" style="width: 426.1pt; padding-top: 0pt; padding-right: 5.4pt; padding-bottom: 0pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ccffcc; background-position: initial initial; background-repeat: initial initial; ">
            <p class="p0" style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><font face="宋体">一开始,</font></span><span style="mso-spacerun:'yes'; color:rgb(153,51,0); font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">&#949;-closure(s)</span><span style="mso-spacerun:'yes'; color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><font face="宋体">是DStates中的唯一状态，且没有被标记;</font></span><span style="color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            <p class="p0" style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; ">while&nbsp;(DStates<font face="宋体">中存在未被标识的状态T)&nbsp;{</font></span><span style="color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            <p class="p0" style="margin-left:21.0000pt; margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><font face="宋体">标识T;</font></span><span style="color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            <p class="p0" style="margin-left:21.0000pt; margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; ">for(<font face="宋体">每个输入符号a)&nbsp;{</font></span><span style="color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            <p class="p0" style="margin-left:42.0000pt; margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; ">U&nbsp;=&nbsp;</span><span style="mso-spacerun:'yes'; color:rgb(153,51,0); font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">&#949;-closure(</span><span style="mso-spacerun:'yes'; color:rgb(153,51,0); font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">move(T,a)</span><span style="color:rgb(153,51,0); font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">)</span><span style="color:rgb(153,51,0); font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">;</span><span style="color:rgb(153,51,0); font-weight:bold; font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            <p class="p0" style="margin-left:42.0000pt; margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; color:rgb(0,0,128); font-weight:normal; font-size:10.5000pt; font-family:'宋体'; ">if(U不再DStats中)&nbsp;将U加入DStates，且没有标识;</span><span style="color:rgb(0,0,128); font-weight:normal; font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            <p class="p0" style="margin-left:42.0000pt; margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; color:rgb(0,0,128); font-weight:normal; font-size:10.5000pt; font-family:'宋体'; ">Dtran[T,a]&nbsp;=&nbsp;U;</span><span style="color:rgb(0,0,128); font-weight:bold; font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            <p class="p0" style="margin-left:21.0000pt; margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; ">}</span><span style="color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            <p class="p0" style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; ">}</span><span style="color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            </td>
        </tr>
    </tbody>
</table>
<p class="p0" style="margin-left:42.0000pt; text-indent:-21.0000pt; margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; color:rgb(51,51,153); font-size:14.0000pt; font-family:'Wingdings'; ">&#216;&nbsp;</span><span style="mso-spacerun:'yes'; color:rgb(51,51,153); font-size:14.0000pt; font-family:'宋体'; ">计算</span><span style="mso-spacerun:'yes'; color:rgb(51,51,153); font-weight:bold; font-size:14.0000pt; font-family:'宋体'; ">&#949;-closure(T)的算法</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
<table style="border-collapse: collapse; ">
    <tbody>
        <tr>
            <td width="568" valign="top" style="width: 426.1pt; padding-top: 0pt; padding-right: 5.4pt; padding-bottom: 0pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ccffcc; background-position: initial initial; background-repeat: initial initial; ">
            <p class="p0" style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><font face="宋体">将T的所有状态压入堆栈中;</font></span><span style="color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            <p class="p0" style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><font face="宋体">将</font></span><span style="mso-spacerun:'yes'; color:rgb(153,51,0); font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">&#949;-closure(</span><span style="color:rgb(153,51,0); font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">T</span><span style="color:rgb(153,51,0); font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">)</span><span style="mso-spacerun:'yes'; color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><font face="宋体">的内容初始化为T;</font></span><span style="color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            <p class="p0" style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; ">while&nbsp;(<font face="宋体">堆栈非空)&nbsp;{</font></span><span style="color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            <p class="p0" style="margin-left:21.0000pt; margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><font face="宋体">将栈顶元素t弹出;</font></span><span style="color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            <p class="p0" style="margin-left:21.0000pt; margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; ">for(<font face="宋体">每个满足如下条件的u：从t出发有一个标号为</font></span><span style="color:rgb(153,51,0); font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">&#949;</span><span style="mso-spacerun:'yes'; color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><font face="宋体">的转换到达状态u)</font></span><span style="color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            <p class="p0" style="margin-left:42.0000pt; margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; ">if(u<font face="宋体">不再</font></span><span style="mso-spacerun:'yes'; color:rgb(153,51,0); font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">&#949;-closure(</span><span style="color:rgb(153,51,0); font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">T</span><span style="color:rgb(153,51,0); font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">)</span><span style="mso-spacerun:'yes'; color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><font face="宋体">中){</font></span><span style="color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            <p class="p0" style="margin-left:63.0000pt; margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><font face="宋体">将u加入到</font></span><span style="mso-spacerun:'yes'; color:rgb(153,51,0); font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">&#949;-closure(</span><span style="color:rgb(153,51,0); font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">T</span><span style="color:rgb(153,51,0); font-weight:bold; font-size:10.5000pt; font-family:'宋体'; ">)</span><span style="mso-spacerun:'yes'; color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><font face="宋体">中;</font></span><span style="color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            <p class="p0" style="margin-left:63.0000pt; margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><font face="宋体">将u压入栈中;</font></span><span style="color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            <p class="p0" style="margin-left:42.0000pt; margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; ">}</span><span style="color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            <p class="p0" style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; ">}</span><span style="color:rgb(0,0,128); font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            </td>
        </tr>
    </tbody>
</table>
<p class="p0" style="margin-left:42.0000pt; text-indent:-21.0000pt; margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'Wingdings'; ">&#216;&nbsp;</span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; "><font face="宋体">附模拟一个NFA</font></span><span style="mso-spacerun:'yes'; font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
<table style="border-collapse: collapse; ">
    <tbody>
        <tr>
            <td width="568" valign="top" style="width: 426.1pt; padding-top: 0pt; padding-right: 5.4pt; padding-bottom: 0pt; padding-left: 5.4pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ccffcc; background-position: initial initial; background-repeat: initial initial; ">
            <p class="p0" style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; color:rgb(51,51,153); font-weight:normal; font-size:14.0000pt; font-family:'宋体'; ">S&nbsp;=&nbsp;</span><span style="mso-spacerun:'yes'; color:rgb(153,51,0); font-weight:bold; font-size:14.0000pt; font-family:'宋体'; ">&#949;-closure(s</span><span style="color:rgb(153,51,0); font-weight:bold; font-size:14.0000pt; font-family:'宋体'; vertical-align:sub; ">0</span><span style="mso-spacerun:'yes'; color:rgb(153,51,0); font-weight:bold; font-size:14.0000pt; font-family:'宋体'; ">);</span><span style="color:rgb(51,51,153); font-weight:normal; font-size:14.0000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            <p class="p0" style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; color:rgb(51,51,153); font-weight:normal; font-size:14.0000pt; font-family:'宋体'; ">c&nbsp;=&nbsp;nextChar();</span><span style="color:rgb(51,51,153); font-weight:normal; font-size:14.0000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            <p class="p0" style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; color:rgb(51,51,153); font-weight:normal; font-size:14.0000pt; font-family:'宋体'; ">while(c&nbsp;!=&nbsp;eof)&nbsp;{</span><span style="color:rgb(51,51,153); font-weight:normal; font-size:14.0000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            <p class="p0" style="margin-left:21.0000pt; margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; color:rgb(51,51,153); font-weight:normal; font-size:14.0000pt; font-family:'宋体'; ">S&nbsp;=&nbsp;</span><span style="mso-spacerun:'yes'; color:rgb(153,51,0); font-weight:bold; font-size:14.0000pt; font-family:'宋体'; ">&#949;-closure(move(S,c))</span><span style="color:rgb(153,51,0); font-weight:normal; font-size:14.0000pt; font-family:'宋体'; ">;</span><span style="color:rgb(51,51,153); font-weight:normal; font-size:14.0000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            <p class="p0" style="margin-left:21.0000pt; margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; color:rgb(51,51,153); font-weight:normal; font-size:14.0000pt; font-family:'宋体'; ">c&nbsp;=&nbsp;nextChar();</span><span style="color:rgb(51,51,153); font-weight:normal; font-size:14.0000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            <p class="p0" style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="color:rgb(51,51,153); font-weight:normal; font-size:14.0000pt; font-family:'宋体'; ">}</span><span style="color:rgb(51,51,153); font-weight:normal; font-size:14.0000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            <p class="p0" style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; color:rgb(51,51,153); font-weight:normal; font-size:14.0000pt; font-family:'宋体'; ">if(S&nbsp;&#8745;&nbsp;F&nbsp;!=&nbsp;&#248;)&nbsp;return&nbsp;true;</span><span style="color:rgb(51,51,153); font-weight:normal; font-size:14.0000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            <p class="p0" style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; color:rgb(51,51,153); font-weight:normal; font-size:14.0000pt; font-family:'宋体'; ">else&nbsp;return&nbsp;false;</span><span style="font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
            </td>
        </tr>
    </tbody>
</table>
<p class="p0" style="margin-bottom:0pt; margin-top:0pt; text-align:justify; "><span style="mso-spacerun:'yes'; color:rgb(51,51,153); font-weight:normal; font-size:10.5000pt; font-family:'宋体'; "><o:p></o:p></span></p>
</div>
</strong></span></font><br />
</p>
<img src ="http://www.blogjava.net/zhaochengming/aggbug/316084.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zhaochengming/" target="_blank">helloworld2008</a> 2010-03-21 16:17 <a href="http://www.blogjava.net/zhaochengming/archive/2010/03/21/316084.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>KMP算法</title><link>http://www.blogjava.net/zhaochengming/archive/2010/03/21/316045.html</link><dc:creator>helloworld2008</dc:creator><author>helloworld2008</author><pubDate>Sat, 20 Mar 2010 17:14:00 GMT</pubDate><guid>http://www.blogjava.net/zhaochengming/archive/2010/03/21/316045.html</guid><wfw:comment>http://www.blogjava.net/zhaochengming/comments/316045.html</wfw:comment><comments>http://www.blogjava.net/zhaochengming/archive/2010/03/21/316045.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zhaochengming/comments/commentRss/316045.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zhaochengming/services/trackbacks/316045.html</trackback:ping><description><![CDATA[<div class="Section0" style="layout-grid:  15.6pt none">
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-weight: bold; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">KMP<font face="宋体">算法</font></span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'">KMP<font face="宋体">算法是一种改进的字符串匹配算法，此算法可以在O(n+m)的时间数量级上完成串的模式匹配操作，基本思想是，每当匹配过程中出现字符串比较不等时，不需回溯指针，而是利用已经得到的&#8220;部分匹配&#8221;结果将模式向右&#8220;滑动&#8221;尽可能远的一段距离，据徐进行比较。</font></span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">定义：</font></span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'">①　</span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">要搜索的关键字符串&nbsp;</font></span><span style="font-weight: bold; font-size: 10.5pt; color: rgb(128,0,0); font-family: '宋体'; mso-spacerun: 'yes'">key&nbsp;</span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">K</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">K</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">2</span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">......K</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">m</span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">。</font></span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'">②　</span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">被搜索的源字符串&nbsp;</font></span><span style="font-weight: bold; font-size: 10.5pt; color: rgb(128,0,0); font-family: '宋体'; mso-spacerun: 'yes'">source&nbsp;</span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">S</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">S</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">2</span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">.....</span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">S</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">n</span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">。</font></span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; margin-left: 0.05pt; text-indent: 21pt"><span style="font-size: 10.5pt; font-family: 'Wingdings'; mso-spacerun: 'yes'">u&nbsp;</span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">针对要查找的关键字字符串构造失效函数f(s)，该函数的功能就是在比较当</font></span><span style="font-size: 15pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">K</span><span style="font-size: 15pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">i&nbsp;</span><span style="font-size: 15pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">!=&nbsp;S</span><span style="font-size: 15pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">j</span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">的时候计算出从K的第多少个字符开始重新比较。</font></span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; margin-left: 0.15pt; text-indent: 21pt; text-align: justify"><span style="font-size: 10.5pt; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">使得</font></span><span style="font-size: 14pt; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'">K</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-size: 14pt; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'">K</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'">2</span><span style="font-size: 14pt; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'">...K</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'">f(s)</span><span style="font-size: 10.5pt; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">是最长的既是</font></span><span style="font-size: 14pt; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'">K</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-size: 14pt; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'">K</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'">2</span><span style="font-size: 14pt; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'">...K</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'">s</span><span style="font-size: 10.5pt; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">的的真前缀，又是</font></span><span style="font-size: 14pt; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'">K</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-size: 14pt; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'">K</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'">2</span><span style="font-size: 14pt; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'">...K</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'">s</span><span style="font-size: 10.5pt; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">的后缀的字串</font></span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">。也就是说如果我们试图用一个文本串</font></span><span style="font-weight: bold; font-size: 10.5pt; color: rgb(128,0,0); font-family: '宋体'; mso-spacerun: 'yes'">x</span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">匹配</font></span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">K</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">K</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">2</span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">......K</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">m</span><span style="font-size: 10.5pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">，</font></span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">并且我们已经匹配了前i个字符，但匹配K</font></span><span style="font-size: 10.5pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">i+1</span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">的时候失败，也就是说</font></span><span style="font-weight: bold; font-size: 10.5pt; color: rgb(128,0,0); font-family: '宋体'; mso-spacerun: 'yes'">x</span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">的下一个位置不是K</font></span><span style="font-size: 10.5pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">i+1</span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">，那么f(s)就是可能和我们当前位置为结尾的文本串匹配的最长的</font></span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">K</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">K</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">2</span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">......K</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">m</span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">的前缀和后缀</font></span><span style="font-weight: bold; font-size: 10.5pt; color: rgb(128,0,0); font-family: '宋体'; mso-spacerun: 'yes'">y</span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">。也就是说文本</font></span><span style="font-weight: bold; font-size: 10.5pt; color: rgb(128,0,0); font-family: '宋体'; mso-spacerun: 'yes'">x</span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">的下一个位置和</font></span><span style="font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">K</span><span style="font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">f(s)</span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">比较，</font></span><span style="font-weight: bold; font-size: 10.5pt; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'">X<font face="宋体">当前位置之前的f(s)个字符和K</font></span><span style="font-weight: bold; font-size: 10.5pt; vertical-align: sub; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-weight: bold; font-size: 10.5pt; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'">..K</span><span style="font-weight: bold; font-size: 10.5pt; vertical-align: sub; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'">f(s)</span><span style="font-weight: bold; font-size: 10.5pt; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">是匹配的</font></span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">。所以直接从K</font></span><span style="font-size: 10.5pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">f(s)</span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">之后进行比较。</font></span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; margin-left: -21pt; text-indent: 21pt; text-align: justify"><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">算法如下：</font></span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<table style="border-collapse: collapse; mso-table-layout-alt: fixed">
    <tbody>
        <tr>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: rgb(0,0,0) 0.5pt solid; padding-left: 5.4pt; background: rgb(192,192,192); padding-bottom: 0pt; border-left: rgb(0,0,0) 0.5pt solid; width: 426.1pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="568">
            <p class="p0" style="margin-top: 0pt; background: rgb(192,192,192); margin-bottom: 0pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">t&nbsp;=&nbsp;0;</span><span style="font-weight: normal; font-size: 10.5pt; color: rgb(0,0,255); font-family: '宋体'"><o:p></o:p></span></p>
            <p class="p0" style="margin-top: 0pt; background: rgb(192,192,192); margin-bottom: 0pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">f(1)&nbsp;=&nbsp;0;</span><span style="font-weight: normal; font-size: 10.5pt; color: rgb(0,0,255); font-family: '宋体'"><o:p></o:p></span></p>
            <p class="p0" style="margin-top: 0pt; background: rgb(192,192,192); margin-bottom: 0pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">for&nbsp;(i&nbsp;=&nbsp;1;&nbsp;i&nbsp;&lt;&nbsp;m;&nbsp;i++)&nbsp;{</span><span style="font-weight: normal; font-size: 10.5pt; color: rgb(0,0,255); font-family: '宋体'"><o:p></o:p></span></p>
            <p class="p0" style="margin-top: 0pt; background: rgb(192,192,192); margin-bottom: 0pt; margin-left: 21pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">while(t&nbsp;&gt;&nbsp;0&nbsp;&amp;&amp;&nbsp;(</span><span style="font-weight: normal; font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'">K</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">i+1&nbsp;</span><span style="font-weight: normal; font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">!=&nbsp;K</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">t+1)</span><span style="font-weight: normal; font-size: 10.5pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">)&nbsp;t&nbsp;=&nbsp;f(t);</span><span style="font-weight: normal; font-size: 10.5pt; color: rgb(0,0,255); font-family: '宋体'"><o:p></o:p></span></p>
            <p class="p0" style="margin-top: 0pt; background: rgb(192,192,192); margin-bottom: 0pt; margin-left: 21pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">if(</span><span style="font-weight: normal; font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'">K</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">i+1&nbsp;</span><span style="font-weight: normal; font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">==&nbsp;K</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">t+1</span><span style="font-weight: normal; font-size: 10.5pt; color: rgb(0,0,255); font-family: '宋体'">)</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'">&nbsp;</span><span style="font-weight: normal; font-size: 10.5pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'">{</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'"><o:p></o:p></span></p>
            <p class="p0" style="margin-top: 0pt; background: rgb(192,192,192); margin-bottom: 0pt; margin-left: 42pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">t&nbsp;=&nbsp;t&nbsp;+&nbsp;1;</span><span style="font-weight: normal; font-size: 10.5pt; color: rgb(0,0,255); font-family: '宋体'"><o:p></o:p></span></p>
            <p class="p0" style="margin-top: 0pt; background: rgb(192,192,192); margin-bottom: 0pt; margin-left: 42pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">f(i+1)&nbsp;=&nbsp;t;</span><span style="font-weight: normal; font-size: 10.5pt; color: rgb(0,0,255); font-family: '宋体'"><o:p></o:p></span></p>
            <p class="p0" style="margin-top: 0pt; background: rgb(192,192,192); margin-bottom: 0pt; margin-left: 21pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">}&nbsp;else&nbsp;f(i+1)&nbsp;=&nbsp;0;</span><span style="font-weight: normal; font-size: 10.5pt; color: rgb(0,0,255); font-family: '宋体'"><o:p></o:p></span></p>
            <p class="p0" style="margin-top: 0pt; background: rgb(192,192,192); margin-bottom: 0pt; text-align: justify"><span style="font-weight: normal; font-size: 10.5pt; color: rgb(0,0,255); font-family: '宋体'">}</span><span style="font-size: 10.5pt; color: rgb(0,128,0); font-family: '宋体'"><o:p></o:p></span></p>
            </td>
        </tr>
    </tbody>
</table>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; margin-left: 20.9pt; text-align: justify"><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; margin-left: 0.1pt; text-align: justify"><span style="font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">对于串</font></span><span style="font-size: 14pt; color: rgb(51,51,153); font-family: '宋体'; mso-spacerun: 'yes'">"a&nbsp;b&nbsp;a&nbsp;b&nbsp;a&nbsp;a"</span><span style="font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">的计算f(s)的过程如下：</font></span><span style="font-size: 16pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<table style="border-collapse: collapse; mso-table-layout-alt: fixed">
    <tbody>
        <tr>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: rgb(0,0,0) 0.5pt solid; padding-left: 5.4pt; background: rgb(255,204,153); padding-bottom: 0pt; border-left: rgb(0,0,0) 0.5pt solid; width: 40.75pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="54">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-weight: bold; font-size: 14pt; font-family: '宋体'">s</span><span style="font-weight: bold; font-size: 14pt; font-family: '宋体'"><o:p></o:p></span></p>
            </td>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: rgb(0,0,0) 0.5pt solid; padding-left: 5.4pt; background: rgb(255,204,153); padding-bottom: 0pt; border-left: medium none; width: 48.75pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="65">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-weight: bold; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">f(s)</span><span style="font-weight: bold; font-size: 14pt; font-family: '宋体'"><o:p></o:p></span></p>
            </td>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: rgb(0,0,0) 0.5pt solid; padding-left: 5.4pt; background: rgb(255,204,153); padding-bottom: 0pt; border-left: medium none; width: 89.25pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="119">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: bold; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">当前字符串</span><span style="font-size: 14pt; font-family: '宋体'"><o:p></o:p></span></p>
            </td>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: rgb(0,0,0) 0.5pt solid; padding-left: 5.4pt; background: rgb(255,204,153); padding-bottom: 0pt; border-left: medium none; width: 247.35pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="329">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: bold; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">说明</span><span style="font-size: 14pt; font-family: '宋体'"><o:p></o:p></span></p>
            </td>
        </tr>
        <tr>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; background: rgb(204,255,204); padding-bottom: 0pt; border-left: rgb(0,0,0) 0.5pt solid; width: 40.75pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="54">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'">1</span><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'"><o:p></o:p></span></p>
            </td>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; background: rgb(204,255,204); padding-bottom: 0pt; border-left: medium none; width: 48.75pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="65">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'">0</span><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'"><o:p></o:p></span></p>
            </td>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; background: rgb(204,255,204); padding-bottom: 0pt; border-left: medium none; width: 89.25pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="119">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'">a</span><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'"><o:p></o:p></span></p>
            </td>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; background: rgb(204,255,204); padding-bottom: 0pt; border-left: medium none; width: 247.35pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="329">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: bold; font-size: 10.5pt; color: rgb(128,0,0); font-family: '宋体'; mso-spacerun: 'yes'">无真前缀</span><span style="font-weight: bold; font-size: 10.5pt; color: rgb(128,0,0); font-family: '宋体'"><o:p></o:p></span></p>
            </td>
        </tr>
        <tr>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; background: rgb(204,255,204); padding-bottom: 0pt; border-left: rgb(0,0,0) 0.5pt solid; width: 40.75pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="54">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'">2</span><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'"><o:p></o:p></span></p>
            </td>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; background: rgb(204,255,204); padding-bottom: 0pt; border-left: medium none; width: 48.75pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="65">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'">0</span><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'"><o:p></o:p></span></p>
            </td>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; background: rgb(204,255,204); padding-bottom: 0pt; border-left: medium none; width: 89.25pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="119">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'">ab</span><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'"><o:p></o:p></span></p>
            </td>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; background: rgb(204,255,204); padding-bottom: 0pt; border-left: medium none; width: 247.35pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="329">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: bold; font-size: 10.5pt; color: rgb(128,0,0); font-family: '宋体'; mso-spacerun: 'yes'">无真前缀</span><span style="font-weight: bold; font-size: 10.5pt; color: rgb(128,0,0); font-family: '宋体'"><o:p></o:p></span></p>
            </td>
        </tr>
        <tr>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; background: rgb(204,255,204); padding-bottom: 0pt; border-left: rgb(0,0,0) 0.5pt solid; width: 40.75pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="54">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'">3</span><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'"><o:p></o:p></span></p>
            </td>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; background: rgb(204,255,204); padding-bottom: 0pt; border-left: medium none; width: 48.75pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="65">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'">1</span><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'"><o:p></o:p></span></p>
            </td>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; background: rgb(204,255,204); padding-bottom: 0pt; border-left: medium none; width: 89.25pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="119">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'">aba</span><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'"><o:p></o:p></span></p>
            </td>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; background: rgb(204,255,204); padding-bottom: 0pt; border-left: medium none; width: 247.35pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="329">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: bold; font-size: 10.5pt; color: rgb(128,0,0); font-family: '宋体'; mso-spacerun: 'yes'">"a"是"aba"的真前缀和后缀</span><span style="font-weight: bold; font-size: 10.5pt; color: rgb(128,0,0); font-family: '宋体'"><o:p></o:p></span></p>
            </td>
        </tr>
        <tr>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; background: rgb(204,255,204); padding-bottom: 0pt; border-left: rgb(0,0,0) 0.5pt solid; width: 40.75pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="54">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'">4</span><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'"><o:p></o:p></span></p>
            </td>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; background: rgb(204,255,204); padding-bottom: 0pt; border-left: medium none; width: 48.75pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="65">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'">2</span><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'"><o:p></o:p></span></p>
            </td>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; background: rgb(204,255,204); padding-bottom: 0pt; border-left: medium none; width: 89.25pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="119">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'">abab</span><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'"><o:p></o:p></span></p>
            </td>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; background: rgb(204,255,204); padding-bottom: 0pt; border-left: medium none; width: 247.35pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="329">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: bold; font-size: 10.5pt; color: rgb(128,0,0); font-family: '宋体'; mso-spacerun: 'yes'">"ab"是"abab"的真前缀和后缀</span><span style="font-weight: bold; font-size: 10.5pt; color: rgb(128,0,0); font-family: '宋体'"><o:p></o:p></span></p>
            </td>
        </tr>
        <tr>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; background: rgb(204,255,204); padding-bottom: 0pt; border-left: rgb(0,0,0) 0.5pt solid; width: 40.75pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="54">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'">5</span><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'"><o:p></o:p></span></p>
            </td>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; background: rgb(204,255,204); padding-bottom: 0pt; border-left: medium none; width: 48.75pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="65">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'">3</span><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'"><o:p></o:p></span></p>
            </td>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; background: rgb(204,255,204); padding-bottom: 0pt; border-left: medium none; width: 89.25pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="119">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'">ababa</span><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'"><o:p></o:p></span></p>
            </td>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; background: rgb(204,255,204); padding-bottom: 0pt; border-left: medium none; width: 247.35pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="329">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: bold; font-size: 10.5pt; color: rgb(128,0,0); font-family: '宋体'; mso-spacerun: 'yes'">"ab</span><span style="font-weight: bold; font-size: 10.5pt; color: rgb(128,0,0); font-family: '宋体'">a</span><span style="font-weight: bold; font-size: 10.5pt; color: rgb(128,0,0); font-family: '宋体'; mso-spacerun: 'yes'">"是"abab</span><span style="font-weight: bold; font-size: 10.5pt; color: rgb(128,0,0); font-family: '宋体'">a</span><span style="font-weight: bold; font-size: 10.5pt; color: rgb(128,0,0); font-family: '宋体'; mso-spacerun: 'yes'">"的真前缀和后缀</span><span style="font-weight: bold; font-size: 10.5pt; color: rgb(128,0,0); font-family: '宋体'"><o:p></o:p></span></p>
            </td>
        </tr>
        <tr>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; background: rgb(204,255,204); padding-bottom: 0pt; border-left: rgb(0,0,0) 0.5pt solid; width: 40.75pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="54">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'">6</span><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'"><o:p></o:p></span></p>
            </td>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; background: rgb(204,255,204); padding-bottom: 0pt; border-left: medium none; width: 48.75pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="65">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'">1</span><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'"><o:p></o:p></span></p>
            </td>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; background: rgb(204,255,204); padding-bottom: 0pt; border-left: medium none; width: 89.25pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="119">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'">ababaa</span><span style="font-weight: bold; font-size: 10.5pt; font-family: '宋体'"><o:p></o:p></span></p>
            </td>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; background: rgb(204,255,204); padding-bottom: 0pt; border-left: medium none; width: 247.35pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="329">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: bold; font-size: 10.5pt; color: rgb(128,0,0); font-family: '宋体'; mso-spacerun: 'yes'">"a"是"abab</span><span style="font-weight: bold; font-size: 10.5pt; color: rgb(128,0,0); font-family: '宋体'; mso-spacerun: 'yes'">aa</span><span style="font-weight: bold; font-size: 10.5pt; color: rgb(128,0,0); font-family: '宋体'; mso-spacerun: 'yes'">"的真前缀和后缀</span><span style="font-weight: bold; font-size: 10.5pt; color: rgb(128,0,0); font-family: '宋体'"><o:p></o:p></span></p>
            </td>
        </tr>
    </tbody>
</table>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; margin-left: 0.1pt; text-align: justify"><span style="font-size: 10.5pt; font-family: 'Wingdings'; mso-spacerun: 'yes'">u&nbsp;</span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">针检查</font></span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">S</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">S</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">2</span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">.....</span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">S</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">n</span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">是否包含关键字</font></span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">K</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">K</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">2</span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">......K</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">m</span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">的算法</font></span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><font face="宋体">。</font></span><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<table style="border-collapse: collapse; mso-table-layout-alt: fixed">
    <tbody>
        <tr>
            <td style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: rgb(0,0,0) 0.5pt solid; padding-left: 5.4pt; background: rgb(192,192,192); padding-bottom: 0pt; border-left: rgb(0,0,0) 0.5pt solid; width: 426.1pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid" valign="top" width="568">
            <p class="p0" style="margin-top: 0pt; background: rgb(192,192,192); margin-bottom: 0pt; text-align: justify"><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">s&nbsp;=&nbsp;0;</span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'"><o:p></o:p></span></p>
            <p class="p0" style="margin-top: 0pt; background: rgb(192,192,192); margin-bottom: 0pt; text-align: justify"><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">for&nbsp;(i&nbsp;=&nbsp;1;&nbsp;i&nbsp;&lt;=&nbsp;n&nbsp;i++)&nbsp;{&nbsp;&nbsp;&nbsp;//&nbsp;<font face="宋体">下标从1开始</font></span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'"><o:p></o:p></span></p>
            <p class="p0" style="margin-top: 0pt; background: rgb(192,192,192); margin-bottom: 0pt; margin-left: 21pt; text-align: justify"><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">while&nbsp;(s&nbsp;&gt;&nbsp;0&nbsp;&amp;&amp;&nbsp;S</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'">i</span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;!=&nbsp;K</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">s+1</span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">)&nbsp;s&nbsp;=&nbsp;f(s);</span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'"><o:p></o:p></span></p>
            <p class="p0" style="margin-top: 0pt; background: rgb(192,192,192); margin-bottom: 0pt; margin-left: 21pt; text-align: justify"><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">if(S</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'">i</span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;==&nbsp;K</span><span style="font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">s+1</span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">)&nbsp;s&nbsp;=&nbsp;s&nbsp;+&nbsp;1;</span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'"><o:p></o:p></span></p>
            <p class="p0" style="margin-top: 0pt; background: rgb(192,192,192); margin-bottom: 0pt; margin-left: 21pt; text-align: justify"><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">if(s&nbsp;==&nbsp;n)&nbsp;return&nbsp;"yes";</span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'"><o:p></o:p></span></p>
            <p class="p0" style="margin-top: 0pt; background: rgb(192,192,192); margin-bottom: 0pt; text-align: justify"><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'">}</span><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'"><o:p></o:p></span></p>
            <p class="p0" style="margin-top: 0pt; background: rgb(192,192,192); margin-bottom: 0pt; text-align: justify"><span style="font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">return&nbsp;"no";</span><span style="font-size: 10.5pt; color: rgb(0,0,255); font-family: '宋体'"><o:p></o:p></span></p>
            </td>
        </tr>
    </tbody>
</table>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; margin-left: 0.1pt; text-align: justify"><span style="font-size: 10.5pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
</div>
<p><!--endfragment--></p>
<img src ="http://www.blogjava.net/zhaochengming/aggbug/316045.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zhaochengming/" target="_blank">helloworld2008</a> 2010-03-21 01:14 <a href="http://www.blogjava.net/zhaochengming/archive/2010/03/21/316045.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>文法的化简与改造</title><link>http://www.blogjava.net/zhaochengming/archive/2009/07/06/285613.html</link><dc:creator>helloworld2008</dc:creator><author>helloworld2008</author><pubDate>Sun, 05 Jul 2009 16:45:00 GMT</pubDate><guid>http://www.blogjava.net/zhaochengming/archive/2009/07/06/285613.html</guid><wfw:comment>http://www.blogjava.net/zhaochengming/comments/285613.html</wfw:comment><comments>http://www.blogjava.net/zhaochengming/archive/2009/07/06/285613.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zhaochengming/comments/commentRss/285613.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zhaochengming/services/trackbacks/285613.html</trackback:ping><description><![CDATA[<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">文法的化简与改造</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">1、无用符号及无用产生式的删除&nbsp;</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">无用符号：设有一文法G[S]=&nbsp;（V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;，V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">T</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;，P，S），说G中的一个符号X&#8712;V是有用的是指X至少出现在一个句子的推导过程中，即满足：</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">存在&#945;，&#946;&#8712;V*，有S=*&gt;&#945;X&#946;&nbsp;</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">存在&#969;&#8712;V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">T</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">*&nbsp;，&#945;X&#946;=*&gt;&#969;</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">否则X为无用符号</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">设有文法G[S]=&nbsp;（V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;，V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">T</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;，P，S），首先用算法2.1改造该文法的到G1[S]=&nbsp;（V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;，V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">T</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;，P</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">，S），使得对于每一个X&#8712;V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">，都有&#969;&#8712;V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">T</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">*，X=*&gt;&#969;</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'">算法1：&nbsp;</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">(1)&nbsp;</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">分别置V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">，P</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">为&#934;。</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">(2)&nbsp;</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">对P中每一个产生式A&#8594;&#948;，若&#948;&#8712;V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">T</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">*，则将A放入V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">中。</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">(3)&nbsp;</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">对P中每一个产生式A&#8594;X</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;X</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">2</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&#8230;&#8230;X</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">K</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">，若每一个X</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">i</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;都属于V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">T</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">或V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">，则将A放入V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">中。</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">(4)&nbsp;</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">重复③直至V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">不增大。</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">(5)&nbsp;</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">对于P中的每一个产生式B&#8594;Y</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;Y</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">2</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&#8230;&#8230;Y</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">n</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;，若B及每一个Y</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">i</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;，都属于V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&#8746;V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">T</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;&nbsp;，则将B&#8594;Y</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;Y</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">2</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&#8230;&#8230;Y</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">n</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">，放入P</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">中。&nbsp;</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">其次，对以给文法G[S]，若执行算法2.2可得到一等价文法G&#8217;=（V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&#8217;，&nbsp;V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">T</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&#8217;&nbsp;，P&#8217;，S）使得对任一X&#8712;V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&#8217;&#8746;&nbsp;V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">T</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&#8217;都存在&#945;，&#946;&#8712;（V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&#8217;&#8746;&nbsp;V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">T</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&#8217;）有S=*&gt;&#945;X&#946;.&nbsp;</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'">算法2:</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">1.分别置V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&#8217;、&nbsp;V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">T</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&#8217;、P&#8217;为&#966;</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">2.将S&nbsp;放入V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&#8217;中。</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">3.对于G中任何型如A&#8594;&#945;</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">|&#8230;&#8230;|&#945;</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">m</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">的产生式，若A&#8712;V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&#8217;则将&#945;</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&#8230;&#8230;&#945;</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">m</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;中的全部非终结符放入V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&#8217;中，终结符放入V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">T</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&#8217;中。</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">4.重复③直至V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&#8217;、&nbsp;V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">T</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&#8217;不增大为止。</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">5.将P中左右部仅含V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&#8217;&#8746;&nbsp;V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">T</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&#8217;中符号的所有产生式放入P&#8217;&nbsp;中。&nbsp;</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">2、&#949;—产生式的消除</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">有的分析方法要求文法中不能含有&#949;—产生式，因此需要改造文法使之不含&#949;—产生式。</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">如果语言不含有&#949;句子，则可有办法消除文法中的全部&#949;—产生式，否则不可能全部消除，但我们希望只有在空句子的推导中用到&#949;—产生式，其他语句的推导过程中不会使用&#949;—产生式。故对含有空句子的文法，我们希望只有文法开始符S&#8594;&#949;这样一个产生式并且S不出现在其它任何产生式的右部。</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'">算法3：</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">找出所有能导出&#949;的非终结符。</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">1.构造W</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">={A|产生式A&#8594;&#949;&#8712;P}</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">2.构造集合序列W</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">K+1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">=&nbsp;W</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">K</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&#8746;{B|B&#8594;&#946;&#8712;P，且&#946;&#8712;W</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">K</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">，K&#8805;1}</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;&nbsp;W</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">K+1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">是一个有限集，设最后的W</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">K+1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">为W。</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">当S&#8712;W时，&#949;&#8712;L（G[S]）。</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">设有一文法G[S]=&nbsp;（V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;，V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">T</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;，P，S），当&#949;不属于该文法所描述的语言时，可构造文法：</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">G&#8217;=（V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">，V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">T</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">，P&#8217;，S），使得L（G&#8217;）=L（G），G&#8217;不含有&#949;产生式：</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'">算法4:</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">1.利用W将V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;分为两个子集W及V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;-W。</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">2.设A&#8594;X</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;X</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">2</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&#8230;&#8230;X</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">K</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&#8712;P，按下面规则将所有型如A&#8594;Y</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;Y</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">2</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&#8230;&#8230;Y</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">K</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;的产生式放入P&#8217;中，对于一切1&#8804;i&#8804;k：</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;&nbsp;a．若X</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">i</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;不属于W，则取Y</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">i</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;=&nbsp;X</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">i</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">b．若X</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">i</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;&#8712;W，则分别取Y</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">i</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;为X</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">i</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">与&#949;，但是若所有X</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">i</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">均属于W，却不能把所有Y</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">i</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;取为&#949;。&nbsp;</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">设有一文法G[S]=&nbsp;（V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;，V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">T</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;，P，S），当&#949;属于该文法所描述的语言时，可构造文法：</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">G1=（V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;，V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">T</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;，P</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">，S&#8217;），使得L（G</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">）=L（G），P</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">中除S&#8217;&#8594;&#949;外不再含有其它&#949;产生式，并且S&#8217;不出现在任何产生式的右边。</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; color: rgb(255,0,0); font-family: '宋体'; mso-spacerun: 'yes'">算法5：</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">若S不出现在任何产生式的右部，则可直接用算法2.4消除&#949;产生式，再加入S&#8594;&#949;，否则：</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;&nbsp;1．引入新的非终结符S&#8217;，&nbsp;V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">=&nbsp;V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;&#8746;{&nbsp;S&#8217;}</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;&nbsp;2．构造P&#8217;&nbsp;=P&#8746;{&nbsp;S&#8217;&#8594;&#945;|&nbsp;S&#8594;&#945;&#8712;P}</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;&nbsp;3．对文法G1=（V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">1&nbsp;，V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">T</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;，P</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">，S&#8217;），执行算法4，再加入S&#8217;&#8594;&#949;。&nbsp;</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">3、单产生式的消除</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">A&#8594;B，A,B&#8712;V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;此类产生式被称为单产生式。</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">假定文法中不含有&#949;产生式。</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">算法6：</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">设V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;={&nbsp;A</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;......&nbsp;A</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;}&nbsp;对每一个A</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">i</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;（1&#8804;i&#8804;n）构造集合序列</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">W</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">(&nbsp;A</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">i</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">）={A</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">i</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">}，&nbsp;</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">W</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">K+1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">（A</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">i</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;）=&nbsp;W</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">K</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">（A</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">i</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;）&#8746;{D|C&#8594;D&#8712;P，C&#8712;W</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">K</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">（A</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">i</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;），D&#8712;V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;}</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">K&#8805;1，该集合序列存在一个j，有</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">W</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">j</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">（A</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">i</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;）=&nbsp;W</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">j+1</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">（A</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">i</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;）......</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">令W（i）=&nbsp;W</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">j</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">（A</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">i</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;）</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">W（i）={B|&nbsp;A</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">i</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;=&gt;B，B&#8712;V</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">N</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;}</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">构造P&#8217;={&nbsp;A</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; font-family: '宋体'; mso-spacerun: 'yes'">i</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">&nbsp;&#8594;&#945;|B&#8594;&#945;&#8712;P，B&#8712;W（i），&#945;不是单个非终结符}</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">(</span><span style="font-weight: normal; font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">对于A</span><span style="font-weight: normal; font-size: 14pt; vertical-align: sub; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">1</span><span style="font-weight: normal; font-size: 14pt; color: rgb(0,0,255); font-family: '宋体'; mso-spacerun: 'yes'">到A<sub>n</sub>的U操作</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">),</span><span style="font-weight: normal; font-size: 14pt; font-family: '宋体'; mso-spacerun: 'yes'">此时P&#8242;中已不含任何单产生式。</span></p>
<!--endfragment-->
 <img src ="http://www.blogjava.net/zhaochengming/aggbug/285613.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zhaochengming/" target="_blank">helloworld2008</a> 2009-07-06 00:45 <a href="http://www.blogjava.net/zhaochengming/archive/2009/07/06/285613.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>日期函数</title><link>http://www.blogjava.net/zhaochengming/archive/2008/01/10/174346.html</link><dc:creator>helloworld2008</dc:creator><author>helloworld2008</author><pubDate>Thu, 10 Jan 2008 08:54:00 GMT</pubDate><guid>http://www.blogjava.net/zhaochengming/archive/2008/01/10/174346.html</guid><wfw:comment>http://www.blogjava.net/zhaochengming/comments/174346.html</wfw:comment><comments>http://www.blogjava.net/zhaochengming/archive/2008/01/10/174346.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zhaochengming/comments/commentRss/174346.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zhaochengming/services/trackbacks/174346.html</trackback:ping><description><![CDATA[<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080">&nbsp;1</span>&nbsp;<span style="color: #000000"><br />
</span><span style="color: #008080">&nbsp;2</span>&nbsp;<span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;ComputerWeek&nbsp;{<br />
</span><span style="color: #008080">&nbsp;3</span>&nbsp;<span style="color: #000000"><br />
</span><span style="color: #008080">&nbsp;4</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">/**</span><span style="color: #008000"><br />
</span><span style="color: #008080">&nbsp;5</span>&nbsp;<span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;计算某一个日期是星期几<br />
</span><span style="color: #008080">&nbsp;6</span>&nbsp;<span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</span><span style="color: #808080">@param</span><span style="color: #008000">&nbsp;year&nbsp;年<br />
</span><span style="color: #008080">&nbsp;7</span>&nbsp;<span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</span><span style="color: #808080">@param</span><span style="color: #008000">&nbsp;month&nbsp;月<br />
</span><span style="color: #008080">&nbsp;8</span>&nbsp;<span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</span><span style="color: #808080">@param</span><span style="color: #008000">&nbsp;day&nbsp;日<br />
</span><span style="color: #008080">&nbsp;9</span>&nbsp;<span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</span><span style="color: #808080">@return</span><span style="color: #008000">&nbsp;星期<br />
</span><span style="color: #008080">10</span>&nbsp;<span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">*/</span><span style="color: #000000"><br />
</span><span style="color: #008080">11</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;getWeek(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;year,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;month,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;day)&nbsp;{<br />
</span><span style="color: #008080">12</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;首先我们知道2008-01-07是星期一</span><span style="color: #008000"><br />
</span><span style="color: #008080">13</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;weeks[]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;{</span><span style="color: #000000">1</span><span style="color: #000000">,</span><span style="color: #000000">2</span><span style="color: #000000">,</span><span style="color: #000000">3</span><span style="color: #000000">,</span><span style="color: #000000">4</span><span style="color: #000000">,</span><span style="color: #000000">5</span><span style="color: #000000">,</span><span style="color: #000000">6</span><span style="color: #000000">,</span><span style="color: #000000">7</span><span style="color: #000000">};<br />
</span><span style="color: #008080">14</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;standardDay&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;getDaysFromAD(</span><span style="color: #000000">2008</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">7</span><span style="color: #000000">);<br />
</span><span style="color: #008080">15</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;temps&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;getDaysFromAD(year,month,day);<br />
</span><span style="color: #008080">16</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;temps&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;temps&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;standardDay;<br />
</span><span style="color: #008080">17</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(temps&nbsp;</span><span style="color: #000000">&gt;=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">)&nbsp;{<br />
</span><span style="color: #008080">18</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;temps&nbsp;</span><span style="color: #000000">%=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">7</span><span style="color: #000000">;<br />
</span><span style="color: #008080">19</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;weeks[temps];<br />
</span><span style="color: #008080">20</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;{<br />
</span><span style="color: #008080">21</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;temps&nbsp;</span><span style="color: #000000">%=</span><span style="color: #000000">7</span><span style="color: #000000">;<br />
</span><span style="color: #008080">22</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;temps&nbsp;</span><span style="color: #000000">+=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">7</span><span style="color: #000000">;<br />
</span><span style="color: #008080">23</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;temps&nbsp;</span><span style="color: #000000">%=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">7</span><span style="color: #000000">;<br />
</span><span style="color: #008080">24</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;weeks[temps];<br />
</span><span style="color: #008080">25</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: #008080">26</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: #008080">27</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #008080">28</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">/**</span><span style="color: #008000"><br />
</span><span style="color: #008080">29</span>&nbsp;<span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;计算从公元1年1月1号&nbsp;到这个日期的天数<br />
</span><span style="color: #008080">30</span>&nbsp;<span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</span><span style="color: #808080">@param</span><span style="color: #008000">&nbsp;year<br />
</span><span style="color: #008080">31</span>&nbsp;<span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</span><span style="color: #808080">@param</span><span style="color: #008000">&nbsp;month<br />
</span><span style="color: #008080">32</span>&nbsp;<span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</span><span style="color: #808080">@param</span><span style="color: #008000">&nbsp;day<br />
</span><span style="color: #008080">33</span>&nbsp;<span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</span><span style="color: #808080">@return</span><span style="color: #008000"><br />
</span><span style="color: #008080">34</span>&nbsp;<span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">*/</span><span style="color: #000000"><br />
</span><span style="color: #008080">35</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;getDaysFromAD(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;year,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;month,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;day)&nbsp;{<br />
</span><span style="color: #008080">36</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;days&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />
</span><span style="color: #008080">37</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;year;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)&nbsp;{<br />
</span><span style="color: #008080">38</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(isLeapYear(i))&nbsp;{<br />
</span><span style="color: #008080">39</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;days&nbsp;</span><span style="color: #000000">+=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">366</span><span style="color: #000000">;<br />
</span><span style="color: #008080">40</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;{<br />
</span><span style="color: #008080">41</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;days&nbsp;</span><span style="color: #000000">+=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">365</span><span style="color: #000000">;<br />
</span><span style="color: #008080">42</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: #008080">43</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: #008080">44</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;month;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)&nbsp;{<br />
</span><span style="color: #008080">45</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(i&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">3</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">5</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">7</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">8</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">10</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">12</span><span style="color: #000000">)&nbsp;{<br />
</span><span style="color: #008080">46</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;days&nbsp;</span><span style="color: #000000">+=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">31</span><span style="color: #000000">;<br />
</span><span style="color: #008080">47</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(i&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">)&nbsp;{<br />
</span><span style="color: #008080">48</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(isLeapYear(year))&nbsp;{<br />
</span><span style="color: #008080">49</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;days&nbsp;</span><span style="color: #000000">+=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">29</span><span style="color: #000000">;<br />
</span><span style="color: #008080">50</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;{<br />
</span><span style="color: #008080">51</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;days&nbsp;</span><span style="color: #000000">+=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">28</span><span style="color: #000000">;<br />
</span><span style="color: #008080">52</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: #008080">53</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;{<br />
</span><span style="color: #008080">54</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;days&nbsp;</span><span style="color: #000000">+=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">30</span><span style="color: #000000">;<br />
</span><span style="color: #008080">55</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: #008080">56</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: #008080">57</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;days&nbsp;</span><span style="color: #000000">+=</span><span style="color: #000000">&nbsp;day;<br />
</span><span style="color: #008080">58</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;days;<br />
</span><span style="color: #008080">59</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: #008080">60</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #008080">61</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">/**</span><span style="color: #008000"><br />
</span><span style="color: #008080">62</span>&nbsp;<span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;判断是否为闰年<br />
</span><span style="color: #008080">63</span>&nbsp;<span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</span><span style="color: #808080">@param</span><span style="color: #008000">&nbsp;year<br />
</span><span style="color: #008080">64</span>&nbsp;<span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</span><span style="color: #808080">@return</span><span style="color: #008000"><br />
</span><span style="color: #008080">65</span>&nbsp;<span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">*/</span><span style="color: #000000"><br />
</span><span style="color: #008080">66</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">boolean</span><span style="color: #000000">&nbsp;isLeapYear(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;year)&nbsp;{<br />
</span><span style="color: #008080">67</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;((year&nbsp;</span><span style="color: #000000">%</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">4</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;year&nbsp;</span><span style="color: #000000">%</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">100</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">)&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;(year&nbsp;</span><span style="color: #000000">%</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">400</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">))&nbsp;{<br />
</span><span style="color: #008080">68</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">true</span><span style="color: #000000">;<br />
</span><span style="color: #008080">69</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;{<br />
</span><span style="color: #008080">70</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">false</span><span style="color: #000000">;<br />
</span><span style="color: #008080">71</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: #008080">72</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: #008080">73</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #008080">74</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;main(String&nbsp;args[])&nbsp;{<br />
</span><span style="color: #008080">75</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;ComputerWeek().getWeek(</span><span style="color: #000000">2008</span><span style="color: #000000">,</span><span style="color: #000000">12</span><span style="color: #000000">,</span><span style="color: #000000">31</span><span style="color: #000000">));<br />
</span><span style="color: #008080">76</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: #008080">77</span>&nbsp;<span style="color: #000000">}<br />
</span><span style="color: #008080">78</span>&nbsp;</div>
 <img src ="http://www.blogjava.net/zhaochengming/aggbug/174346.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zhaochengming/" target="_blank">helloworld2008</a> 2008-01-10 16:54 <a href="http://www.blogjava.net/zhaochengming/archive/2008/01/10/174346.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>