﻿<?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>C++博客-Charles-随笔分类-面试小算法</title><link>http://www.cppblog.com/Winux32/category/3062.html</link><description>Thinking low level, Coding high level</description><language>zh-cn</language><lastBuildDate>Tue, 20 May 2008 00:53:22 GMT</lastBuildDate><pubDate>Tue, 20 May 2008 00:53:22 GMT</pubDate><ttl>60</ttl><item><title>Integer Partition</title><link>http://www.cppblog.com/Winux32/archive/2006/12/06/16056.html</link><dc:creator>Charles</dc:creator><author>Charles</author><pubDate>Wed, 06 Dec 2006 09:59:00 GMT</pubDate><guid>http://www.cppblog.com/Winux32/archive/2006/12/06/16056.html</guid><wfw:comment>http://www.cppblog.com/Winux32/comments/16056.html</wfw:comment><comments>http://www.cppblog.com/Winux32/archive/2006/12/06/16056.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Winux32/comments/commentRss/16056.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Winux32/services/trackbacks/16056.html</trackback:ping><description><![CDATA[
		<p>
				<font face="Verdana" color="#0000ff" size="2">先来个只计算分割数的版本</font>
		</p>
		<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">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> Compute(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> number, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> maximum)<br /><img id="Codehighlighter1_37_301_Open_Image" onclick="this.style.display='none'; Codehighlighter1_37_301_Open_Text.style.display='none'; Codehighlighter1_37_301_Closed_Image.style.display='inline'; Codehighlighter1_37_301_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_37_301_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_37_301_Closed_Text.style.display='none'; Codehighlighter1_37_301_Open_Image.style.display='inline'; Codehighlighter1_37_301_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_37_301_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_37_301_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (number </span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">||</span>
						<span style="COLOR: #000000"> maximum </span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">else</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (number </span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000"> maximum)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> Compute(number, number);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">else</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (number </span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> maximum)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000"> Compute(number, maximum </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">else</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> Compute(number, maximum </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">) </span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000"> Compute(number </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000"> maximum, maximum);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> IntPartionNo(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> n)<br /><img id="Codehighlighter1_328_353_Open_Image" onclick="this.style.display='none'; Codehighlighter1_328_353_Open_Text.style.display='none'; Codehighlighter1_328_353_Closed_Image.style.display='inline'; Codehighlighter1_328_353_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_328_353_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_328_353_Closed_Text.style.display='none'; Codehighlighter1_328_353_Open_Image.style.display='inline'; Codehighlighter1_328_353_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_328_353_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_328_353_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> Compute(n, n);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
		<br />
		<font color="#0000ff">
				<font face="Verdana" size="2">打印所有分割版本<br /></font>
				<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">
						<font face="Verdana">
								<font size="2">
										<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
										<span style="COLOR: #0000ff">int</span>
										<span style="COLOR: #000000"> IntegerPartition(</span>
										<span style="COLOR: #0000ff">int</span>
								</font>
						</font>
						<font face="Verdana">
								<font size="2">
										<span style="COLOR: #000000"> n)<br /><img id="Codehighlighter1_28_838_Open_Image" onclick="this.style.display='none'; Codehighlighter1_28_838_Open_Text.style.display='none'; Codehighlighter1_28_838_Closed_Image.style.display='inline'; Codehighlighter1_28_838_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_28_838_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_28_838_Closed_Text.style.display='none'; Codehighlighter1_28_838_Open_Image.style.display='inline'; Codehighlighter1_28_838_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
										<span id="Codehighlighter1_28_838_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
								</font>
						</font>
						<span id="Codehighlighter1_28_838_Open_Text">
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
												<span style="COLOR: #0000ff">int</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">*</span>
												<span style="COLOR: #000000">partition </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #0000ff">new</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #0000ff">int</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">[n]();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
												<span style="COLOR: #0000ff">int</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">*</span>
												<span style="COLOR: #000000">repeat </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #0000ff">new</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #0000ff">int</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">[n]();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    partition[</span>
												<span style="COLOR: #000000">1</span>
												<span style="COLOR: #000000">] </span>
												<span style="COLOR: #000000">=</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000"> n;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    repeat[</span>
												<span style="COLOR: #000000">1</span>
												<span style="COLOR: #000000">] </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">1</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
												<span style="COLOR: #0000ff">int</span>
												<span style="COLOR: #000000"> count </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">1</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
												<span style="COLOR: #0000ff">int</span>
												<span style="COLOR: #000000"> part </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">1</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
												<span style="COLOR: #0000ff">int</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000"> last, smaller, remainder;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    printf(</span>
												<span style="COLOR: #000000">"</span>
												<span style="COLOR: #000000">%3d</span>
												<span style="COLOR: #000000">"</span>
												<span style="COLOR: #000000">, partition[</span>
												<span style="COLOR: #000000">1</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">]);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
												<span style="COLOR: #0000ff">do</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000"> <br /><img id="Codehighlighter1_227_678_Open_Image" onclick="this.style.display='none'; Codehighlighter1_227_678_Open_Text.style.display='none'; Codehighlighter1_227_678_Closed_Image.style.display='inline'; Codehighlighter1_227_678_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_227_678_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_227_678_Closed_Text.style.display='none'; Codehighlighter1_227_678_Open_Image.style.display='inline'; Codehighlighter1_227_678_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
												<span id="Codehighlighter1_227_678_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
														<img src="http://www.cppblog.com/images/dot.gif" />
												</span>
										</font>
								</font>
								<span id="Codehighlighter1_227_678_Open_Text">
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        last </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> (partition[part] </span>
														<span style="COLOR: #000000">==</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">1</span>
														<span style="COLOR: #000000">) </span>
														<span style="COLOR: #000000">?</span>
														<span style="COLOR: #000000"> (repeat[part</span>
														<span style="COLOR: #000000">--</span>
														<span style="COLOR: #000000">] </span>
														<span style="COLOR: #000000">+</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">1</span>
														<span style="COLOR: #000000">) : </span>
														<span style="COLOR: #000000">1</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        smaller </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> partition[part] </span>
														<span style="COLOR: #000000">-</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">1</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
														<span style="COLOR: #0000ff">if</span>
														<span style="COLOR: #000000"> (repeat[part] </span>
														<span style="COLOR: #000000">!=</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">1</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
														<span style="COLOR: #000000">--</span>
														<span style="COLOR: #000000">repeat[part</span>
														<span style="COLOR: #000000">++</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        partition[part] </span>
														<span style="COLOR: #000000">=</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000"> smaller;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        repeat[part] </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">1</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">+</span>
														<span style="COLOR: #000000"> last </span>
														<span style="COLOR: #000000">/</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000"> smaller;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
														<span style="COLOR: #0000ff">if</span>
														<span style="COLOR: #000000"> ((remainder </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> last </span>
														<span style="COLOR: #000000">%</span>
														<span style="COLOR: #000000"> smaller) </span>
														<span style="COLOR: #000000">!=</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">0</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_478_537_Open_Image" onclick="this.style.display='none'; Codehighlighter1_478_537_Open_Text.style.display='none'; Codehighlighter1_478_537_Closed_Image.style.display='inline'; Codehighlighter1_478_537_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_478_537_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_478_537_Closed_Text.style.display='none'; Codehighlighter1_478_537_Open_Image.style.display='inline'; Codehighlighter1_478_537_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
														<span id="Codehighlighter1_478_537_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
																<img src="http://www.cppblog.com/images/dot.gif" />
														</span>
												</font>
										</font>
										<span id="Codehighlighter1_478_537_Open_Text">
												<font face="Verdana">
														<font size="2">
																<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            partition[</span>
																<span style="COLOR: #000000">++</span>
																<span style="COLOR: #000000">part] </span>
																<span style="COLOR: #000000">=</span>
														</font>
												</font>
												<font face="Verdana">
														<font size="2">
																<span style="COLOR: #000000"> remainder;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            repeat[part] </span>
																<span style="COLOR: #000000">=</span>
																<span style="COLOR: #000000"> </span>
																<span style="COLOR: #000000">1</span>
														</font>
												</font>
												<span style="COLOR: #000000">
														<font face="Verdana" size="2">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</font>
												</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<font face="Verdana" size="2">
														<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
														<br />
														<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </font>
										</span>
										<span style="COLOR: #000000">
												<font face="Verdana" size="2">++</font>
										</span>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000">count;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        printf(</span>
														<span style="COLOR: #000000">"</span>
														<span style="COLOR: #000000">\n</span>
														<span style="COLOR: #000000">"</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
														<span style="COLOR: #0000ff">for</span>
														<span style="COLOR: #000000"> (</span>
														<span style="COLOR: #0000ff">int</span>
														<span style="COLOR: #000000"> i </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">1</span>
														<span style="COLOR: #000000">; i </span>
														<span style="COLOR: #000000">&lt;=</span>
														<span style="COLOR: #000000"> part; </span>
														<span style="COLOR: #000000">++</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000">i)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
														<span style="COLOR: #0000ff">for</span>
														<span style="COLOR: #000000"> (</span>
														<span style="COLOR: #0000ff">int</span>
														<span style="COLOR: #000000"> j </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">1</span>
														<span style="COLOR: #000000">; j </span>
														<span style="COLOR: #000000">&lt;=</span>
														<span style="COLOR: #000000"> repeat[i]; </span>
														<span style="COLOR: #000000">++</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000">j)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                printf(</span>
														<span style="COLOR: #000000">"</span>
														<span style="COLOR: #000000">%3d</span>
														<span style="COLOR: #000000">"</span>
												</font>
										</font>
										<span style="COLOR: #000000">
												<font face="Verdana" size="2">, partition[i]);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</font>
										</span>
								</span>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #0000ff">while</span>
												<span style="COLOR: #000000">(repeat[part] </span>
												<span style="COLOR: #000000">!=</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000"> n);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
												<span style="COLOR: #0000ff">if</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000"> (partition)<br /><img id="Codehighlighter1_724_767_Open_Image" onclick="this.style.display='none'; Codehighlighter1_724_767_Open_Text.style.display='none'; Codehighlighter1_724_767_Closed_Image.style.display='inline'; Codehighlighter1_724_767_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_724_767_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_724_767_Closed_Text.style.display='none'; Codehighlighter1_724_767_Open_Image.style.display='inline'; Codehighlighter1_724_767_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
												<span id="Codehighlighter1_724_767_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
														<img src="http://www.cppblog.com/images/dot.gif" />
												</span>
										</font>
								</font>
								<span id="Codehighlighter1_724_767_Open_Text">
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        delete [] partition;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        partition </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">0</span>
												</font>
										</font>
										<span style="COLOR: #000000">
												<font face="Verdana" size="2">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</font>
										</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<font face="Verdana" size="2">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </font>
								</span>
								<span style="COLOR: #0000ff">
										<font face="Verdana" size="2">if</font>
								</span>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000"> (repeat)<br /><img id="Codehighlighter1_783_820_Open_Image" onclick="this.style.display='none'; Codehighlighter1_783_820_Open_Text.style.display='none'; Codehighlighter1_783_820_Closed_Image.style.display='inline'; Codehighlighter1_783_820_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_783_820_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_783_820_Closed_Text.style.display='none'; Codehighlighter1_783_820_Open_Image.style.display='inline'; Codehighlighter1_783_820_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
												<span id="Codehighlighter1_783_820_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
														<img src="http://www.cppblog.com/images/dot.gif" />
												</span>
										</font>
								</font>
								<span id="Codehighlighter1_783_820_Open_Text">
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        delete [] repeat;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        repeat </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">0</span>
												</font>
										</font>
										<span style="COLOR: #000000">
												<font face="Verdana" size="2">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</font>
										</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<font face="Verdana" size="2">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </font>
								</span>
								<span style="COLOR: #0000ff">
										<font face="Verdana" size="2">return</font>
								</span>
								<span style="COLOR: #000000">
										<font face="Verdana" size="2"> count;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</font>
								</span>
						</span>
				</div>
		</font>
		<font face="Verdana" color="#0000ff" size="2">没有时间把解释写出来，自己根据变量名结合网上原理凑合看吧，真是对不起观众啊</font>
<img src ="http://www.cppblog.com/Winux32/aggbug/16056.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Winux32/" target="_blank">Charles</a> 2006-12-06 17:59 <a href="http://www.cppblog.com/Winux32/archive/2006/12/06/16056.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>数1的个数</title><link>http://www.cppblog.com/Winux32/archive/2006/12/05/16008.html</link><dc:creator>Charles</dc:creator><author>Charles</author><pubDate>Tue, 05 Dec 2006 04:31:00 GMT</pubDate><guid>http://www.cppblog.com/Winux32/archive/2006/12/05/16008.html</guid><wfw:comment>http://www.cppblog.com/Winux32/comments/16008.html</wfw:comment><comments>http://www.cppblog.com/Winux32/archive/2006/12/05/16008.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Winux32/comments/commentRss/16008.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Winux32/services/trackbacks/16008.html</trackback:ping><description><![CDATA[
		<p>
				<font face="Verdana" color="#0000ff" size="2">一般解法</font>
		</p>
		<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">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> CountOne(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> n)<br /><img id="Codehighlighter1_20_96_Open_Image" onclick="this.style.display='none'; Codehighlighter1_20_96_Open_Text.style.display='none'; Codehighlighter1_20_96_Closed_Image.style.display='inline'; Codehighlighter1_20_96_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_20_96_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_20_96_Closed_Text.style.display='none'; Codehighlighter1_20_96_Open_Image.style.display='inline'; Codehighlighter1_20_96_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_20_96_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_20_96_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> count </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">while</span>
						<span style="COLOR: #000000"> (n)<br /><img id="Codehighlighter1_50_78_Open_Image" onclick="this.style.display='none'; Codehighlighter1_50_78_Open_Text.style.display='none'; Codehighlighter1_50_78_Closed_Image.style.display='inline'; Codehighlighter1_50_78_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_50_78_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_50_78_Closed_Text.style.display='none'; Codehighlighter1_50_78_Open_Image.style.display='inline'; Codehighlighter1_50_78_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_50_78_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_50_78_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">count;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        n </span>
								<span style="COLOR: #000000">&amp;=</span>
								<span style="COLOR: #000000"> n </span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> count;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
		<br />
		<font color="#0000ff">
				<font face="Verdana" size="2">快速解法，典型的空间换时间。<br /><br /></font>
				<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">
						<font face="Verdana">
								<font size="2">
										<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
										<span style="COLOR: #0000ff">int</span>
										<span style="COLOR: #000000"> CountOnesUsingTable(unsigned </span>
										<span style="COLOR: #0000ff">int</span>
								</font>
						</font>
						<font face="Verdana">
								<font size="2">
										<span style="COLOR: #000000"> i)<br /><img id="Codehighlighter1_40_749_Open_Image" onclick="this.style.display='none'; Codehighlighter1_40_749_Open_Text.style.display='none'; Codehighlighter1_40_749_Closed_Image.style.display='inline'; Codehighlighter1_40_749_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_40_749_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_40_749_Closed_Text.style.display='none'; Codehighlighter1_40_749_Open_Image.style.display='inline'; Codehighlighter1_40_749_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
										<span id="Codehighlighter1_40_749_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
								</font>
						</font>
						<span id="Codehighlighter1_40_749_Open_Text">
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
												<span style="COLOR: #0000ff">static</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #0000ff">int</span>
												<span style="COLOR: #000000"> BIT_TABLES[</span>
												<span style="COLOR: #000000">256</span>
												<span style="COLOR: #000000">] </span>
												<span style="COLOR: #000000">=</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000"> <br /><img id="Codehighlighter1_74_635_Open_Image" onclick="this.style.display='none'; Codehighlighter1_74_635_Open_Text.style.display='none'; Codehighlighter1_74_635_Closed_Image.style.display='inline'; Codehighlighter1_74_635_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_74_635_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_74_635_Closed_Text.style.display='none'; Codehighlighter1_74_635_Open_Image.style.display='inline'; Codehighlighter1_74_635_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
												<span id="Codehighlighter1_74_635_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
														<img src="http://www.cppblog.com/images/dot.gif" />
												</span>
										</font>
								</font>
								<span id="Codehighlighter1_74_635_Open_Text">
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />     </span>
														<span style="COLOR: #000000">0</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">1</span>
														<span style="COLOR: #000000">,</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">1</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">2</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">1</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">2</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">2</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">3</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">3</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">4</span>
												</font>
										</font>
										<span style="COLOR: #000000">
												<br />
												<font face="Verdana" size="2">
														<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    ,</font>
										</span>
										<font face="Verdana">
												<font size="2">
														<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">2</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">3</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">3</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">4</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">3</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">4</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">4</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">5</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    ,</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">2</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">3</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">3</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">4</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">3</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">4</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">4</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">5</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    ,</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">3</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">4</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">4</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">5</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">4</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">5</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">5</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">6</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    ,</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">2</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">3</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">3</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">4</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">3</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">4</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">4</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">5</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    ,</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">3</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">4</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">4</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">5</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">4</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">5</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">5</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">6</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    ,</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">3</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">4</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">4</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">5</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">4</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">5</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">5</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">6</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    ,</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">4</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">5</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">5</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">6</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">5</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">6</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">6</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">7</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    ,</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">2</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">3</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">3</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">4</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">3</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">4</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">4</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">5</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    ,</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">3</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">4</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">4</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">5</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">4</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">5</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">5</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">6</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    ,</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">3</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">4</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">4</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">5</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">4</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">5</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">5</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">6</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    ,</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">4</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">5</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">5</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">6</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">5</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">6</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">6</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">7</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    ,</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">3</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">4</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">4</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">5</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">4</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">5</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">5</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">6</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    ,</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">4</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">5</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">5</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">6</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">5</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">6</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">6</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">7</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    ,</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">4</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">5</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">5</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">6</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">5</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">6</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">6</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">7</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    ,</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">5</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">6</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">6</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">7</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">6</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">7</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">,</span>
														<span style="COLOR: #000000">7</span>
														<span style="COLOR: #000000">,</span>
														<span style="COLOR: #000000">8</span>
												</font>
										</font>
										<span style="COLOR: #000000">
												<br />
												<font face="Verdana" size="2">
														<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</font>
										</span>
								</span>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
												<span style="COLOR: #0000ff">return</span>
												<span style="COLOR: #000000"> BIT_TABLES[i </span>
												<span style="COLOR: #000000">&amp;</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">255</span>
												<span style="COLOR: #000000">] </span>
												<span style="COLOR: #000000">+</span>
												<span style="COLOR: #000000"> BIT_TABLES[i</span>
												<span style="COLOR: #000000">&gt;&gt;</span>
												<span style="COLOR: #000000">8</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">&amp;</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">255</span>
												<span style="COLOR: #000000">] </span>
												<span style="COLOR: #000000">+</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        BIT_TABLES[i</span>
												<span style="COLOR: #000000">&gt;&gt;</span>
												<span style="COLOR: #000000">16</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">&amp;</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">255</span>
												<span style="COLOR: #000000">] </span>
												<span style="COLOR: #000000">+</span>
												<span style="COLOR: #000000"> BIT_TABLES[i</span>
												<span style="COLOR: #000000">&gt;&gt;</span>
												<span style="COLOR: #000000">24</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">&amp;</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">255</span>
										</font>
								</font>
								<span style="COLOR: #000000">
										<font face="Verdana" size="2">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</font>
								</span>
						</span>
				</div>
		</font>
		<font face="Verdana" color="#0000ff" size="2">事先数好一个字节的所有情况，存成表放到内存里，随用随查。<br />注：第二个代码来自k_eckel，多谢</font>
<img src ="http://www.cppblog.com/Winux32/aggbug/16008.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Winux32/" target="_blank">Charles</a> 2006-12-05 12:31 <a href="http://www.cppblog.com/Winux32/archive/2006/12/05/16008.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Fibonacci</title><link>http://www.cppblog.com/Winux32/archive/2006/12/05/16007.html</link><dc:creator>Charles</dc:creator><author>Charles</author><pubDate>Tue, 05 Dec 2006 04:25:00 GMT</pubDate><guid>http://www.cppblog.com/Winux32/archive/2006/12/05/16007.html</guid><wfw:comment>http://www.cppblog.com/Winux32/comments/16007.html</wfw:comment><comments>http://www.cppblog.com/Winux32/archive/2006/12/05/16007.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/Winux32/comments/commentRss/16007.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Winux32/services/trackbacks/16007.html</trackback:ping><description><![CDATA[
		<font face="Verdana" color="#0000ff" size="2">简单，但可总考尼！验证一下自己是不是眼高手低:p<br /><br />递归<br /><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"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">unsigned </span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000"> FibonacciRec(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> n)<br /><img id="Codehighlighter1_34_119_Open_Image" onclick="this.style.display='none'; Codehighlighter1_34_119_Open_Text.style.display='none'; Codehighlighter1_34_119_Closed_Image.style.display='inline'; Codehighlighter1_34_119_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_34_119_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_34_119_Closed_Text.style.display='none'; Codehighlighter1_34_119_Open_Image.style.display='inline'; Codehighlighter1_34_119_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_34_119_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_34_119_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (n </span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> FibonacciRec(n </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">) </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> FibonacciRec(n </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div></font>
		<br />
		<font face="Verdana" color="#0000ff" size="2">非递归<br /><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"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">unsigned </span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000"> Fibonacci(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> n)<br /><img id="Codehighlighter1_31_162_Open_Image" onclick="this.style.display='none'; Codehighlighter1_31_162_Open_Text.style.display='none'; Codehighlighter1_31_162_Closed_Image.style.display='inline'; Codehighlighter1_31_162_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_31_162_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_31_162_Closed_Text.style.display='none'; Codehighlighter1_31_162_Open_Image.style.display='inline'; Codehighlighter1_31_162_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_31_162_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_31_162_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    unsigned </span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000"> f0 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">, f1 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">, temp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">; i </span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000"> n; i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br /><img id="Codehighlighter1_102_147_Open_Image" onclick="this.style.display='none'; Codehighlighter1_102_147_Open_Text.style.display='none'; Codehighlighter1_102_147_Closed_Image.style.display='inline'; Codehighlighter1_102_147_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_102_147_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_102_147_Closed_Text.style.display='none'; Codehighlighter1_102_147_Open_Image.style.display='inline'; Codehighlighter1_102_147_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_102_147_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_102_147_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        temp </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> f0 </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> f1;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        f0 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> f1;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        f1 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> temp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> f1;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div></font>
<img src ="http://www.cppblog.com/Winux32/aggbug/16007.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Winux32/" target="_blank">Charles</a> 2006-12-05 12:25 <a href="http://www.cppblog.com/Winux32/archive/2006/12/05/16007.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>简单打印内存的小玩意儿</title><link>http://www.cppblog.com/Winux32/archive/2006/12/05/16006.html</link><dc:creator>Charles</dc:creator><author>Charles</author><pubDate>Tue, 05 Dec 2006 04:21:00 GMT</pubDate><guid>http://www.cppblog.com/Winux32/archive/2006/12/05/16006.html</guid><wfw:comment>http://www.cppblog.com/Winux32/comments/16006.html</wfw:comment><comments>http://www.cppblog.com/Winux32/archive/2006/12/05/16006.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Winux32/comments/commentRss/16006.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Winux32/services/trackbacks/16006.html</trackback:ping><description><![CDATA[
		<font color="#0000ff">
				<font face="Verdana" size="2">在学习C++的时候，由于编译器背着我们干了太多的事儿，所以看看那些高级数据结构在汇编级别是怎么样的，在内存中是如何的，对编写高效代码很有帮助。<br />下边是一个小函数，帮你打印内存中的内容。如果使用微软的编译器，各个内存对象之间可能会有byte guard，即编译器会在分配的数据对象之间插入空白bytes，便于检测破坏邻接对象，所以和教科书上的连续分配内存有些差异，注意一下就行了<img height="19" src="http://www.cppblog.com/Emoticons/71_71.gif" width="19" border="0" /><br /></font>
				<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">
						<font face="Verdana">
								<font size="2">
										<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
										<span style="COLOR: #000000">#include </span>
										<span style="COLOR: #000000">&lt;</span>
										<span style="COLOR: #000000">cstdio</span>
										<span style="COLOR: #000000">&gt;</span>
								</font>
						</font>
						<span style="COLOR: #000000">
								<br />
								<font face="Verdana" size="2">
										<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
								</font>
						</span>
						<font face="Verdana">
								<font size="2">
										<span style="COLOR: #0000ff">void</span>
										<span style="COLOR: #000000"> ShowBytes(</span>
										<span style="COLOR: #0000ff">void</span>
										<span style="COLOR: #000000">*</span>
										<span style="COLOR: #000000"> s, </span>
										<span style="COLOR: #0000ff">int</span>
								</font>
						</font>
						<font face="Verdana">
								<font size="2">
										<span style="COLOR: #000000"> n)<br /><img id="Codehighlighter1_49_314_Open_Image" onclick="this.style.display='none'; Codehighlighter1_49_314_Open_Text.style.display='none'; Codehighlighter1_49_314_Closed_Image.style.display='inline'; Codehighlighter1_49_314_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_49_314_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_49_314_Closed_Text.style.display='none'; Codehighlighter1_49_314_Open_Image.style.display='inline'; Codehighlighter1_49_314_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
										<span id="Codehighlighter1_49_314_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
								</font>
						</font>
						<span id="Codehighlighter1_49_314_Open_Text">
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    unsigned </span>
												<span style="COLOR: #0000ff">char</span>
												<span style="COLOR: #000000">*</span>
												<span style="COLOR: #000000"> start </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> (unsigned </span>
												<span style="COLOR: #0000ff">char</span>
												<span style="COLOR: #000000">*</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">)s;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    printf(</span>
												<span style="COLOR: #000000">"</span>
												<span style="COLOR: #000000">[OFFSET] ADDRESS: VALUE\n\n</span>
												<span style="COLOR: #000000">"</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
												<span style="COLOR: #0000ff">for</span>
												<span style="COLOR: #000000"> (</span>
												<span style="COLOR: #0000ff">int</span>
												<span style="COLOR: #000000"> i </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">0</span>
												<span style="COLOR: #000000">; i </span>
												<span style="COLOR: #000000">&lt;</span>
												<span style="COLOR: #000000"> n; i</span>
												<span style="COLOR: #000000">++</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_168_307_Open_Image" onclick="this.style.display='none'; Codehighlighter1_168_307_Open_Text.style.display='none'; Codehighlighter1_168_307_Closed_Image.style.display='inline'; Codehighlighter1_168_307_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_168_307_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_168_307_Closed_Text.style.display='none'; Codehighlighter1_168_307_Open_Image.style.display='inline'; Codehighlighter1_168_307_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
												<span id="Codehighlighter1_168_307_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
														<img src="http://www.cppblog.com/images/dot.gif" />
												</span>
										</font>
								</font>
								<span id="Codehighlighter1_168_307_Open_Text">
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        printf(</span>
														<span style="COLOR: #000000">"</span>
														<span style="COLOR: #000000"> [%.4d] %.8X: %.2X\n</span>
														<span style="COLOR: #000000">"</span>
														<span style="COLOR: #000000">, i, start </span>
														<span style="COLOR: #000000">+</span>
														<span style="COLOR: #000000"> i, </span>
														<span style="COLOR: #000000">*</span>
														<span style="COLOR: #000000">(start </span>
														<span style="COLOR: #000000">+</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000"> i));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
														<span style="COLOR: #0000ff">if</span>
														<span style="COLOR: #000000"> ((i </span>
														<span style="COLOR: #000000">+</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">1</span>
														<span style="COLOR: #000000">) </span>
														<span style="COLOR: #000000">%</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">4</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">==</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">0</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_260_304_Open_Image" onclick="this.style.display='none'; Codehighlighter1_260_304_Open_Text.style.display='none'; Codehighlighter1_260_304_Closed_Image.style.display='inline'; Codehighlighter1_260_304_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_260_304_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_260_304_Closed_Text.style.display='none'; Codehighlighter1_260_304_Open_Image.style.display='inline'; Codehighlighter1_260_304_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
														<span id="Codehighlighter1_260_304_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
																<img src="http://www.cppblog.com/images/dot.gif" />
														</span>
												</font>
										</font>
										<span id="Codehighlighter1_260_304_Open_Text">
												<font face="Verdana">
														<font size="2">
																<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            printf(</span>
																<span style="COLOR: #000000">"</span>
																<span style="COLOR: #000000">----------------------\n</span>
																<span style="COLOR: #000000">"</span>
														</font>
												</font>
												<span style="COLOR: #000000">
														<font face="Verdana" size="2">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</font>
												</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<font face="Verdana" size="2">
														<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</font>
										</span>
								</span>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #008000">//</span>
												<span style="COLOR: #008000">for</span>
										</font>
								</font>
								<span style="COLOR: #008000">
										<br />
										<font face="Verdana" size="2">
												<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />
										</font>
								</span>
								<span style="COLOR: #000000">
										<font face="Verdana" size="2">}</font>
								</span>
						</span>
				</div>
		</font>
		<font face="Verdana" color="#0000ff" size="2">代码很简单，不过用着很方便</font>
<img src ="http://www.cppblog.com/Winux32/aggbug/16006.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Winux32/" target="_blank">Charles</a> 2006-12-05 12:21 <a href="http://www.cppblog.com/Winux32/archive/2006/12/05/16006.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>矩阵式螺旋输出</title><link>http://www.cppblog.com/Winux32/archive/2006/12/04/15958.html</link><dc:creator>Charles</dc:creator><author>Charles</author><pubDate>Mon, 04 Dec 2006 02:08:00 GMT</pubDate><guid>http://www.cppblog.com/Winux32/archive/2006/12/04/15958.html</guid><wfw:comment>http://www.cppblog.com/Winux32/comments/15958.html</wfw:comment><comments>http://www.cppblog.com/Winux32/archive/2006/12/04/15958.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Winux32/comments/commentRss/15958.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Winux32/services/trackbacks/15958.html</trackback:ping><description><![CDATA[
		<img height="239" alt="output1.JPG" src="http://www.cppblog.com/images/cppblog_com/winux32/Output/output1.JPG" width="302" border="0" />
		<br />
		<font face="Verdana" color="#0000ff" size="2">Just like this<br /><br /><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"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cstdio</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> MatrixSpiralOutput(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> n)<br /><img id="Codehighlighter1_49_857_Open_Image" onclick="this.style.display='none'; Codehighlighter1_49_857_Open_Text.style.display='none'; Codehighlighter1_49_857_Closed_Image.style.display='inline'; Codehighlighter1_49_857_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_49_857_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_49_857_Closed_Text.style.display='none'; Codehighlighter1_49_857_Open_Image.style.display='inline'; Codehighlighter1_49_857_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_49_857_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_49_857_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">**</span><span style="COLOR: #000000">matrix </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">[n]();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> idx </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; idx </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> n; idx</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br /><img id="Codehighlighter1_118_151_Open_Image" onclick="this.style.display='none'; Codehighlighter1_118_151_Open_Text.style.display='none'; Codehighlighter1_118_151_Closed_Image.style.display='inline'; Codehighlighter1_118_151_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_118_151_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_118_151_Closed_Text.style.display='none'; Codehighlighter1_118_151_Open_Image.style.display='inline'; Codehighlighter1_118_151_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_118_151_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_118_151_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        matrix[idx] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">[n]();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> row </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">, col </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> len </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> n </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> n;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> circle </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> (i </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> len)<br /><img id="Codehighlighter1_243_576_Open_Image" onclick="this.style.display='none'; Codehighlighter1_243_576_Open_Text.style.display='none'; Codehighlighter1_243_576_Closed_Image.style.display='inline'; Codehighlighter1_243_576_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_243_576_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_243_576_Closed_Text.style.display='none'; Codehighlighter1_243_576_Open_Image.style.display='inline'; Codehighlighter1_243_576_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_243_576_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_243_576_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">( ;row </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> n </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000"> circle; row</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            matrix[row][col] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">i;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        row</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        col</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">( ; col </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> n </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000"> circle; col</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">) <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            matrix[row][col] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">i;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        row</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        col</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">( ; row </span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000"> circle; row</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">) <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            matrix[row][col] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">i;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        row</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        col</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">( ;col </span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> circle; col</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">) <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            matrix[row][col] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">i;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        row</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        col</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        circle</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\n   The  Array matrix[%d][%d] is :</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, n, n);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> k </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; k </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> n; k</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br /><img id="Codehighlighter1_663_754_Open_Image" onclick="this.style.display='none'; Codehighlighter1_663_754_Open_Text.style.display='none'; Codehighlighter1_663_754_Closed_Image.style.display='inline'; Codehighlighter1_663_754_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_663_754_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_663_754_Closed_Text.style.display='none'; Codehighlighter1_663_754_Open_Image.style.display='inline'; Codehighlighter1_663_754_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_663_754_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_663_754_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\n\n      </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> j </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; j </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> n; j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%-5d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, matrix[k][j]);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\n\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> idx </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000"> ; idx </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> n ; idx</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        delete [] matrix[idx];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    delete [] matrix;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div></font>
<img src ="http://www.cppblog.com/Winux32/aggbug/15958.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Winux32/" target="_blank">Charles</a> 2006-12-04 10:08 <a href="http://www.cppblog.com/Winux32/archive/2006/12/04/15958.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>求最大公约数与最小公倍数</title><link>http://www.cppblog.com/Winux32/archive/2006/12/04/15954.html</link><dc:creator>Charles</dc:creator><author>Charles</author><pubDate>Mon, 04 Dec 2006 01:54:00 GMT</pubDate><guid>http://www.cppblog.com/Winux32/archive/2006/12/04/15954.html</guid><wfw:comment>http://www.cppblog.com/Winux32/comments/15954.html</wfw:comment><comments>http://www.cppblog.com/Winux32/archive/2006/12/04/15954.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/Winux32/comments/commentRss/15954.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Winux32/services/trackbacks/15954.html</trackback:ping><description><![CDATA[
		<font face="Verdana" color="#0000ff" size="2">先贴点人家的教学资料<br /><hr /><br /><p align="center"><strong><span style="FONT-FAMILY: 宋体">求最大公约数九法</span></strong></p><p align="center"><span style="FONT-FAMILY: 宋体">湖南省武冈市教研室 周定武</span></p><p>　　<span style="FONT-FAMILY: 宋体">一、<span style="COLOR: blue">观察法</span>．</span></p><p>　　<span style="FONT-FAMILY: 宋体">运用能被<span lang="EN-US">2、3、5整除的数的特征进行观察．</span></span></p><p>　　<span style="FONT-FAMILY: 宋体">例如，求<span lang="EN-US">225和105的最大公约数．因为225、105都能被3和5整除，所以225和105至少含有公约数（3×5）15．因为225÷15＝15，105÷15＝7．15与7互质，所以225和105的最大公约数是15．</span></span></p><p>　　<span style="FONT-FAMILY: 宋体">二、<span style="COLOR: blue">查找约数法</span>．<span lang="EN-US"><br />先分别找出每个数的所有约数，再从两个数的约数中找出公有的约数，其中最大的一个</span></span><span style="FONT-FAMILY: 宋体">就是最大公约数．</span></p><p>　　<span style="FONT-FAMILY: 宋体">例如，求<span lang="EN-US">12和30的最大公约数．<br />12的约数有：1、2、3、4、6、12；<br />30的约数有：1、2、3、5、6、10、15、30．<br />12和30的公约数有：1、2、3、6，其中6就是12和30的最大公约数．</span></span></p><p>　　<span style="FONT-FAMILY: 宋体">三、<span style="COLOR: blue">分解因式法</span>．</span></p><p>　　<span style="FONT-FAMILY: 宋体">先分别把两个数分解质因数，再找出它们全部公有的质因数，然后把这些公有质因数相乘，得到的积就是这两个数的最大公约数．</span></p><p>　　<span style="FONT-FAMILY: 宋体">例如：求<span lang="EN-US">125和300的最大公约数．因为125＝5×5×5，300＝2×2×3×5×5，所以125和300的最大公约数是5×5＝25．</span></span></p><p>　　<span style="FONT-FAMILY: 宋体">四、<span style="COLOR: blue">关系判断法</span>．</span></p><p>　　<span style="FONT-FAMILY: 宋体"><span lang="EN-US">当两个数关系特殊时，可直接判断两个数的最大公约数．例如，两个数互质时，它们的</span></span><span style="FONT-FAMILY: 宋体">最大公约数就是这两个数的乘积；两个数成倍数关系时，它们的最大公约数就是其中较小的那个数．</span></p><p>　　<span style="FONT-FAMILY: 宋体">五、<span style="COLOR: blue">短除法</span>．</span></p><p>　　<span style="FONT-FAMILY: 宋体">为了简便，将两个数的分解过程用同一个短除法来表示，那么最大公约数就是所有除数的乘积．</span></p><p>　　<span style="FONT-FAMILY: 宋体">例如：求<span lang="EN-US">180和324的最大公约数．</span></span></p><p>　　<span style="FONT-FAMILY: 宋体">因为：</span></p><p align="center"><span lang="EN-US" style="FONT-FAMILY: 宋体"><img height="59" src="http://202.201.93.6/zhongyangziyuan/xia/xxpd/jxzy/sx/5/25/01/kzzl/image002.jpg" width="96" v:shapes="_x0000_i1025" /></span></p><p>　　<span style="FONT-FAMILY: 宋体"><span lang="EN-US">5和9互质，所以180和324的最大公约数是4×9＝36．</span></span></p><p>　　<span style="FONT-FAMILY: 宋体">六、<span style="COLOR: blue">除法法</span>．</span></p><p>　　<span style="FONT-FAMILY: 宋体">当两个数中较小的数是质数时，可采用除法求解．即用较大的数除以较小的数，如果能够整除，则较小的数是这两个数的最大公约数．</span></p><p>　　<span style="FONT-FAMILY: 宋体">例如：求<span lang="EN-US">19和152，13和273的最大公约数．因为152÷19＝8，273÷13＝21．（19和13都是质数．）所以19和152的最大公约数是19，13和273的最大公约数是13．</span></span></p><p>　　<span style="FONT-FAMILY: 宋体">七、<span style="COLOR: blue">缩倍法</span>．</span></p><p>　　<span style="FONT-FAMILY: 宋体"><span lang="EN-US">如果两个数没有之间没有倍数关系，可以把较小的数依次除以2、3、4……直到求得的</span></span><span style="FONT-FAMILY: 宋体">商是较大数的约数为止，这时的商就是两个数的最大公约数．例如：求<span lang="EN-US">30和24的最大公约</span>数．<span lang="EN-US">24÷4＝6，6是30的约数，所以30和24的最大公约数是6．</span></span></p><p>　　<span lang="EN-US" style="FONT-FAMILY: 宋体"> 八、<span style="COLOR: blue">求差判定法</span>．</span></p><p>　　<span lang="EN-US" style="FONT-FAMILY: 宋体">如果两个数相差不大，可以用大数减去小数，所得的差与小数的最大公约数就是原来两个数的最大公约数．例如：求78和60的最大公约数．78－60＝18，18和60的最大公约数是6，所以78和60的最大公约数是6．</span></p><p>　　<span lang="EN-US" style="FONT-FAMILY: 宋体"><br />如果两个数相差较大，可以用大数减去小数的若干倍，一直减到差比小数小为止，差和</span><span style="FONT-FAMILY: 宋体">小数的最大公约数就是原来两数的最大公约数．例如：求<span lang="EN-US">92和16的最大公约数．92－16</span></span><span style="FONT-FAMILY: 宋体">＝<span lang="EN-US">76，76－16＝60，60－16＝44，44－16＝28，28－16＝12，12和16的最大公约数是4，</span></span><span style="FONT-FAMILY: 宋体">所以<span lang="EN-US">92和16的最大公约数就是4．</span></span></p><p>　　<span style="FONT-FAMILY: 宋体">九、<span style="COLOR: blue">辗转相除法</span>．</span></p><p>　　<span style="FONT-FAMILY: 宋体">当两个数都较大时，采用辗转相除法比较方便．其方法是：</span></p><p>　　<span style="FONT-FAMILY: 宋体">以小数除大数，如果能整除，那么小数就是所求的最大公约数．否则就用余数来除刚才的除数；再用这新除法的余数去除刚才的余数．依此类推，直到一个除法能够整除，这时作为除数的数就是所求的最大公约数．</span></p><p>　　<span style="FONT-FAMILY: 宋体">例如：求<span lang="EN-US">4453和5767的最大公约数时，可作如下除法．</span></span></p><p>　　<span style="FONT-FAMILY: 宋体"><span lang="EN-US">5767÷4453＝1余1314</span></span></p><p>　　<span style="FONT-FAMILY: 宋体"><span lang="EN-US">4453÷1314＝3余511</span></span></p><p>　　<span style="FONT-FAMILY: 宋体"><span lang="EN-US">1314÷511＝2余292</span></span></p><p>　　<span style="FONT-FAMILY: 宋体"><span lang="EN-US">511÷292＝1余219</span></span></p><p>　　<span style="FONT-FAMILY: 宋体"><span lang="EN-US">292÷219＝1余73</span></span></p><p>　　<span style="FONT-FAMILY: 宋体"><span lang="EN-US">219÷73＝3</span></span></p><p>　　<span style="FONT-FAMILY: 宋体">于是得知，<span lang="EN-US">5767和4453的最大公约数是73．</span></span></p><p>　　<span style="FONT-FAMILY: 宋体">辗转相除法适用比较广，比短除法要好得多，它能保证求出任意两个数的最大公约数．<br /><hr /><br /><br />小学数学温习过后，先来个两个数递归版的<br /></span></p><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"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> GetGCDRec(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> n, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> m)<br /><img id="Codehighlighter1_28_140_Open_Image" onclick="this.style.display='none'; Codehighlighter1_28_140_Open_Text.style.display='none'; Codehighlighter1_28_140_Closed_Image.style.display='inline'; Codehighlighter1_28_140_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_28_140_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_28_140_Closed_Text.style.display='none'; Codehighlighter1_28_140_Open_Image.style.display='inline'; Codehighlighter1_28_140_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_28_140_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_28_140_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (m </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> n)<br /><img id="Codehighlighter1_43_76_Open_Image" onclick="this.style.display='none'; Codehighlighter1_43_76_Open_Text.style.display='none'; Codehighlighter1_43_76_Closed_Image.style.display='inline'; Codehighlighter1_43_76_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_43_76_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_43_76_Closed_Text.style.display='none'; Codehighlighter1_43_76_Open_Image.style.display='inline'; Codehighlighter1_43_76_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_43_76_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_43_76_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        m </span><span style="COLOR: #000000">^=</span><span style="COLOR: #000000"> n;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        n </span><span style="COLOR: #000000">^=</span><span style="COLOR: #000000"> m;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        m </span><span style="COLOR: #000000">^=</span><span style="COLOR: #000000"> n;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (n </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> m;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> GetGCDRec(n, m </span><span style="COLOR: #000000">%</span><span style="COLOR: #000000"> n);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div><p>辗转相除法，求一个数组中所有数的最大公约数<br /></p><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"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> GetGCD(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">arr, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> len)<br /><img id="Codehighlighter1_30_379_Open_Image" onclick="this.style.display='none'; Codehighlighter1_30_379_Open_Text.style.display='none'; Codehighlighter1_30_379_Closed_Image.style.display='inline'; Codehighlighter1_30_379_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_30_379_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_30_379_Closed_Text.style.display='none'; Codehighlighter1_30_379_Open_Image.style.display='inline'; Codehighlighter1_30_379_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_30_379_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_30_379_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> iMax </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> arr[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">], iCurr, iRemainder;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">; i </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> len; i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br /><img id="Codehighlighter1_103_356_Open_Image" onclick="this.style.display='none'; Codehighlighter1_103_356_Open_Text.style.display='none'; Codehighlighter1_103_356_Closed_Image.style.display='inline'; Codehighlighter1_103_356_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_103_356_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_103_356_Closed_Text.style.display='none'; Codehighlighter1_103_356_Open_Image.style.display='inline'; Codehighlighter1_103_356_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_103_356_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_103_356_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        iCurr </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> arr[i];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (iMax </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> iCurr)<br /><img id="Codehighlighter1_146_204_Open_Image" onclick="this.style.display='none'; Codehighlighter1_146_204_Open_Text.style.display='none'; Codehighlighter1_146_204_Closed_Image.style.display='inline'; Codehighlighter1_146_204_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_146_204_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_146_204_Closed_Text.style.display='none'; Codehighlighter1_146_204_Open_Image.style.display='inline'; Codehighlighter1_146_204_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span id="Codehighlighter1_146_204_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_146_204_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            iMax </span><span style="COLOR: #000000">^=</span><span style="COLOR: #000000"> iCurr;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            iCurr </span><span style="COLOR: #000000">^=</span><span style="COLOR: #000000"> iMax;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            iMax </span><span style="COLOR: #000000">^=</span><span style="COLOR: #000000"> iCurr;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        iRemainder </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> iMax </span><span style="COLOR: #000000">%</span><span style="COLOR: #000000"> iCurr;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> (iRemainder)<br /><img id="Codehighlighter1_260_334_Open_Image" onclick="this.style.display='none'; Codehighlighter1_260_334_Open_Text.style.display='none'; Codehighlighter1_260_334_Closed_Image.style.display='inline'; Codehighlighter1_260_334_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_260_334_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_260_334_Closed_Text.style.display='none'; Codehighlighter1_260_334_Open_Image.style.display='inline'; Codehighlighter1_260_334_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span id="Codehighlighter1_260_334_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_260_334_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            iMax </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> iCurr;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            iCurr </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> iRemainder;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            iRemainder </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> iMax </span><span style="COLOR: #000000">%</span><span style="COLOR: #000000"> iCurr;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        iMax </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> iCurr;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">for</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> iMax;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div><p>最小公倍数就是乘积除以最大公约数<br /></p><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"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> GetLCM(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">arr, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> len)<br /><img id="Codehighlighter1_30_143_Open_Image" onclick="this.style.display='none'; Codehighlighter1_30_143_Open_Text.style.display='none'; Codehighlighter1_30_143_Closed_Image.style.display='inline'; Codehighlighter1_30_143_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_30_143_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_30_143_Closed_Text.style.display='none'; Codehighlighter1_30_143_Open_Image.style.display='inline'; Codehighlighter1_30_143_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_30_143_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_30_143_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> multiple </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; i </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> len; i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        multiple </span><span style="COLOR: #000000">*=</span><span style="COLOR: #000000"> arr[i];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> multiple </span><span style="COLOR: #000000">/</span><span style="COLOR: #000000"> GetGCD(arr, len);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div><p><br /><br /><br /> </p></font>
<img src ="http://www.cppblog.com/Winux32/aggbug/15954.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Winux32/" target="_blank">Charles</a> 2006-12-04 09:54 <a href="http://www.cppblog.com/Winux32/archive/2006/12/04/15954.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>数内置类型的bit数</title><link>http://www.cppblog.com/Winux32/archive/2006/12/01/15854.html</link><dc:creator>Charles</dc:creator><author>Charles</author><pubDate>Fri, 01 Dec 2006 08:03:00 GMT</pubDate><guid>http://www.cppblog.com/Winux32/archive/2006/12/01/15854.html</guid><wfw:comment>http://www.cppblog.com/Winux32/comments/15854.html</wfw:comment><comments>http://www.cppblog.com/Winux32/archive/2006/12/01/15854.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Winux32/comments/commentRss/15854.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Winux32/services/trackbacks/15854.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">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">template </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> T</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> CountBits(T n)<br /><img id="Codehighlighter1_38_138_Open_Image" onclick="this.style.display='none'; Codehighlighter1_38_138_Open_Text.style.display='none'; Codehighlighter1_38_138_Closed_Image.style.display='inline'; Codehighlighter1_38_138_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_38_138_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_38_138_Closed_Text.style.display='none'; Codehighlighter1_38_138_Open_Image.style.display='inline'; Codehighlighter1_38_138_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_38_138_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_38_138_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> count;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (count </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">, n </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">~</span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">; <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            n </span>
						<span style="COLOR: #000000">!=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">; <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            n </span>
						<span style="COLOR: #000000">&gt;&gt;=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">count)<br /><img id="Codehighlighter1_113_120_Open_Image" onclick="this.style.display='none'; Codehighlighter1_113_120_Open_Text.style.display='none'; Codehighlighter1_113_120_Closed_Image.style.display='inline'; Codehighlighter1_113_120_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_113_120_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_113_120_Closed_Text.style.display='none'; Codehighlighter1_113_120_Open_Image.style.display='inline'; Codehighlighter1_113_120_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
						<span id="Codehighlighter1_113_120_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span>
						<span id="Codehighlighter1_113_120_Open_Text">
								<span style="COLOR: #008000">/*</span>
								<span style="COLOR: #008000">null</span>
								<span style="COLOR: #008000">*/</span>
						</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> count;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
<img src ="http://www.cppblog.com/Winux32/aggbug/15854.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Winux32/" target="_blank">Charles</a> 2006-12-01 16:03 <a href="http://www.cppblog.com/Winux32/archive/2006/12/01/15854.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>计算Int最大最小值</title><link>http://www.cppblog.com/Winux32/archive/2006/12/01/15853.html</link><dc:creator>Charles</dc:creator><author>Charles</author><pubDate>Fri, 01 Dec 2006 07:55:00 GMT</pubDate><guid>http://www.cppblog.com/Winux32/archive/2006/12/01/15853.html</guid><wfw:comment>http://www.cppblog.com/Winux32/comments/15853.html</wfw:comment><comments>http://www.cppblog.com/Winux32/archive/2006/12/01/15853.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.cppblog.com/Winux32/comments/commentRss/15853.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Winux32/services/trackbacks/15853.html</trackback:ping><description><![CDATA[
		<font color="#0000ff">
				<font face="Verdana" size="2">通常我们会使用CRT提供给我们的一个头文件&lt;limits.h&gt;中预定义宏INT_MAX, INT_MIN, UINT_MAX来定义int的最大最小值<br />下边给出由计算得出这些值的方法，其他数据类型同理<br /></font>
				<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">
						<font face="Verdana">
								<font size="2">
										<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
										<span style="COLOR: #000000">unsigned </span>
										<span style="COLOR: #0000ff">int</span>
								</font>
						</font>
						<font face="Verdana">
								<font size="2">
										<span style="COLOR: #000000"> GetUnsignedIntMax()<br /><img id="Codehighlighter1_33_47_Open_Image" onclick="this.style.display='none'; Codehighlighter1_33_47_Open_Text.style.display='none'; Codehighlighter1_33_47_Closed_Image.style.display='inline'; Codehighlighter1_33_47_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_33_47_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_33_47_Closed_Text.style.display='none'; Codehighlighter1_33_47_Open_Image.style.display='inline'; Codehighlighter1_33_47_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
										<span id="Codehighlighter1_33_47_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
								</font>
						</font>
						<span id="Codehighlighter1_33_47_Open_Text">
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
												<span style="COLOR: #0000ff">return</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">~</span>
												<span style="COLOR: #000000">0</span>
										</font>
								</font>
								<span style="COLOR: #000000">
										<font face="Verdana" size="2">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</font>
								</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<font face="Verdana" size="2">
										<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />signed </font>
						</span>
						<span style="COLOR: #0000ff">
								<font face="Verdana" size="2">int</font>
						</span>
						<font face="Verdana">
								<font size="2">
										<span style="COLOR: #000000"> GetSignedIntMax()<br /><img id="Codehighlighter1_79_127_Open_Image" onclick="this.style.display='none'; Codehighlighter1_79_127_Open_Text.style.display='none'; Codehighlighter1_79_127_Closed_Image.style.display='inline'; Codehighlighter1_79_127_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_79_127_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_79_127_Closed_Text.style.display='none'; Codehighlighter1_79_127_Open_Image.style.display='inline'; Codehighlighter1_79_127_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
										<span id="Codehighlighter1_79_127_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
								</font>
						</font>
						<span id="Codehighlighter1_79_127_Open_Text">
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
												<span style="COLOR: #0000ff">return</span>
												<span style="COLOR: #000000"> (static_cast</span>
												<span style="COLOR: #000000">&lt;</span>
												<span style="COLOR: #000000">unsigned </span>
												<span style="COLOR: #0000ff">int</span>
												<span style="COLOR: #000000">&gt;</span>
												<span style="COLOR: #000000">(</span>
												<span style="COLOR: #000000">~</span>
												<span style="COLOR: #000000">0</span>
												<span style="COLOR: #000000">)) </span>
												<span style="COLOR: #000000">&gt;&gt;</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">1</span>
										</font>
								</font>
								<span style="COLOR: #000000">
										<font face="Verdana" size="2">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</font>
								</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<font face="Verdana" size="2">
										<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />signed </font>
						</span>
						<span style="COLOR: #0000ff">
								<font face="Verdana" size="2">int</font>
						</span>
						<font face="Verdana">
								<font size="2">
										<span style="COLOR: #000000"> GetSignedIntMin()<br /><img id="Codehighlighter1_159_307_Open_Image" onclick="this.style.display='none'; Codehighlighter1_159_307_Open_Text.style.display='none'; Codehighlighter1_159_307_Closed_Image.style.display='inline'; Codehighlighter1_159_307_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_159_307_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_159_307_Closed_Text.style.display='none'; Codehighlighter1_159_307_Open_Image.style.display='inline'; Codehighlighter1_159_307_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
										<span id="Codehighlighter1_159_307_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
								</font>
						</font>
						<span id="Codehighlighter1_159_307_Open_Text">
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    signed </span>
												<span style="COLOR: #0000ff">int</span>
												<span style="COLOR: #000000"> i </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">-</span>
												<span style="COLOR: #000000">1</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
												<span style="COLOR: #0000ff">if</span>
												<span style="COLOR: #000000"> (i </span>
												<span style="COLOR: #000000">&amp;</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">1</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
												<span style="COLOR: #0000ff">return</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">-</span>
												<span style="COLOR: #000000">( (static_cast</span>
												<span style="COLOR: #000000">&lt;</span>
												<span style="COLOR: #000000">unsigned </span>
												<span style="COLOR: #0000ff">int</span>
												<span style="COLOR: #000000">&gt;</span>
												<span style="COLOR: #000000">(</span>
												<span style="COLOR: #000000">~</span>
												<span style="COLOR: #000000">0</span>
												<span style="COLOR: #000000">)) </span>
												<span style="COLOR: #000000">&gt;&gt;</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">1</span>
												<span style="COLOR: #000000"> ) </span>
												<span style="COLOR: #000000">-</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">1</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
												<span style="COLOR: #0000ff">else</span>
										</font>
								</font>
								<span style="COLOR: #000000">
										<br />
										<font face="Verdana" size="2">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </font>
								</span>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #0000ff">return</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">-</span>
												<span style="COLOR: #000000">( (static_cast</span>
												<span style="COLOR: #000000">&lt;</span>
												<span style="COLOR: #000000">unsigned </span>
												<span style="COLOR: #0000ff">int</span>
												<span style="COLOR: #000000">&gt;</span>
												<span style="COLOR: #000000">(</span>
												<span style="COLOR: #000000">~</span>
												<span style="COLOR: #000000">0</span>
												<span style="COLOR: #000000">)) </span>
												<span style="COLOR: #000000">&gt;&gt;</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">1</span>
										</font>
								</font>
								<span style="COLOR: #000000">
										<font face="Verdana" size="2"> );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</font>
								</span>
						</span>
				</div>
		</font>
		<font face="Verdana" color="#0000ff" size="2">稍微解释一下，前两个没有什么好说的，最后一个要考虑是two complement还是one complement<br />如果是前者，有这样一个计算公式，~X + 1= -X，即一个数取反加一表示这个数所对应的负数</font>
<img src ="http://www.cppblog.com/Winux32/aggbug/15853.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Winux32/" target="_blank">Charles</a> 2006-12-01 15:55 <a href="http://www.cppblog.com/Winux32/archive/2006/12/01/15853.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>两个堆栈模拟一个队列</title><link>http://www.cppblog.com/Winux32/archive/2006/11/26/15678.html</link><dc:creator>Charles</dc:creator><author>Charles</author><pubDate>Sun, 26 Nov 2006 10:45:00 GMT</pubDate><guid>http://www.cppblog.com/Winux32/archive/2006/11/26/15678.html</guid><wfw:comment>http://www.cppblog.com/Winux32/comments/15678.html</wfw:comment><comments>http://www.cppblog.com/Winux32/archive/2006/11/26/15678.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/Winux32/comments/commentRss/15678.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Winux32/services/trackbacks/15678.html</trackback:ping><description><![CDATA[
		<font face="Verdana" color="#0000ff" size="2">被考过两次<br /><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"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> ZStackQueue<br /><img id="Codehighlighter1_18_312_Open_Image" onclick="this.style.display='none'; Codehighlighter1_18_312_Open_Text.style.display='none'; Codehighlighter1_18_312_Closed_Image.style.display='inline'; Codehighlighter1_18_312_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_18_312_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_18_312_Closed_Text.style.display='none'; Codehighlighter1_18_312_Open_Image.style.display='inline'; Codehighlighter1_18_312_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_18_312_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_18_312_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> ZStack<br /><img id="Codehighlighter1_43_199_Open_Image" onclick="this.style.display='none'; Codehighlighter1_43_199_Open_Text.style.display='none'; Codehighlighter1_43_199_Closed_Image.style.display='inline'; Codehighlighter1_43_199_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_43_199_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_43_199_Closed_Text.style.display='none'; Codehighlighter1_43_199_Open_Image.style.display='inline'; Codehighlighter1_43_199_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_43_199_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_43_199_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        ZStack(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> size);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">ZStack();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> Pop();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> Push(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> e);<br /><img id="Codehighlighter1_135_152_Open_Image" onclick="this.style.display='none'; Codehighlighter1_135_152_Open_Text.style.display='none'; Codehighlighter1_135_152_Closed_Image.style.display='inline'; Codehighlighter1_135_152_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_135_152_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_135_152_Closed_Text.style.display='none'; Codehighlighter1_135_152_Open_Image.style.display='inline'; Codehighlighter1_135_152_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000"> Empty()</span><span id="Codehighlighter1_135_152_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_135_152_Open_Text"><span style="COLOR: #000000">{</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> top </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;}</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">s;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> top;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> size;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br /><img id="Codehighlighter1_245_246_Open_Image" onclick="this.style.display='none'; Codehighlighter1_245_246_Open_Text.style.display='none'; Codehighlighter1_245_246_Closed_Image.style.display='inline'; Codehighlighter1_245_246_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_245_246_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_245_246_Closed_Text.style.display='none'; Codehighlighter1_245_246_Open_Image.style.display='inline'; Codehighlighter1_245_246_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    ZStackQueue(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> n) : s1(n), s2(n)</span><span id="Codehighlighter1_245_246_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_245_246_Open_Text"><span style="COLOR: #000000">{}</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> EnQueue(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> e);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> DeQueue();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    ZStack s1, s2;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />ZStackQueue::ZStack::ZStack(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> n)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />: s(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">), top(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">), size(n)<br /><img id="Codehighlighter1_375_399_Open_Image" onclick="this.style.display='none'; Codehighlighter1_375_399_Open_Text.style.display='none'; Codehighlighter1_375_399_Closed_Image.style.display='inline'; Codehighlighter1_375_399_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_375_399_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_375_399_Closed_Text.style.display='none'; Codehighlighter1_375_399_Open_Image.style.display='inline'; Codehighlighter1_375_399_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_375_399_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_375_399_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    s </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">[size]();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />ZStackQueue::ZStack::</span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">ZStack()<br /><img id="Codehighlighter1_433_495_Open_Image" onclick="this.style.display='none'; Codehighlighter1_433_495_Open_Text.style.display='none'; Codehighlighter1_433_495_Closed_Image.style.display='inline'; Codehighlighter1_433_495_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_433_495_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_433_495_Closed_Text.style.display='none'; Codehighlighter1_433_495_Open_Image.style.display='inline'; Codehighlighter1_433_495_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_433_495_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_433_495_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (s)<br /><img id="Codehighlighter1_444_471_Open_Image" onclick="this.style.display='none'; Codehighlighter1_444_471_Open_Text.style.display='none'; Codehighlighter1_444_471_Closed_Image.style.display='inline'; Codehighlighter1_444_471_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_444_471_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_444_471_Closed_Text.style.display='none'; Codehighlighter1_444_471_Open_Image.style.display='inline'; Codehighlighter1_444_471_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_444_471_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_444_471_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        delete [] s;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        s </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    top </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    size </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> ZStackQueue::ZStack::Pop()<br /><img id="Codehighlighter1_529_583_Open_Image" onclick="this.style.display='none'; Codehighlighter1_529_583_Open_Text.style.display='none'; Codehighlighter1_529_583_Closed_Image.style.display='inline'; Codehighlighter1_529_583_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_529_583_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_529_583_Closed_Text.style.display='none'; Codehighlighter1_529_583_Open_Image.style.display='inline'; Codehighlighter1_529_583_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_529_583_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_529_583_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (top </span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> s[</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">top];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> ZStackQueue::ZStack::Push(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> e)<br /><img id="Codehighlighter1_624_659_Open_Image" onclick="this.style.display='none'; Codehighlighter1_624_659_Open_Text.style.display='none'; Codehighlighter1_624_659_Closed_Image.style.display='inline'; Codehighlighter1_624_659_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_624_659_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_624_659_Closed_Text.style.display='none'; Codehighlighter1_624_659_Open_Image.style.display='inline'; Codehighlighter1_624_659_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_624_659_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_624_659_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (top </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> size)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        s[top</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> e;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> ZStackQueue::EnQueue(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> e)<br /><img id="Codehighlighter1_695_710_Open_Image" onclick="this.style.display='none'; Codehighlighter1_695_710_Open_Text.style.display='none'; Codehighlighter1_695_710_Closed_Image.style.display='inline'; Codehighlighter1_695_710_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_695_710_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_695_710_Closed_Text.style.display='none'; Codehighlighter1_695_710_Open_Image.style.display='inline'; Codehighlighter1_695_710_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_695_710_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_695_710_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    s1.Push(e);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> ZStackQueue::DeQueue()<br /><img id="Codehighlighter1_740_862_Open_Image" onclick="this.style.display='none'; Codehighlighter1_740_862_Open_Text.style.display='none'; Codehighlighter1_740_862_Closed_Image.style.display='inline'; Codehighlighter1_740_862_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_740_862_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_740_862_Closed_Text.style.display='none'; Codehighlighter1_740_862_Open_Image.style.display='inline'; Codehighlighter1_740_862_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_740_862_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_740_862_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">s2.Empty())<br /><img id="Codehighlighter1_761_783_Open_Image" onclick="this.style.display='none'; Codehighlighter1_761_783_Open_Text.style.display='none'; Codehighlighter1_761_783_Closed_Image.style.display='inline'; Codehighlighter1_761_783_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_761_783_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_761_783_Closed_Text.style.display='none'; Codehighlighter1_761_783_Open_Image.style.display='inline'; Codehighlighter1_761_783_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_761_783_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_761_783_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> s2.Pop();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br /><img id="Codehighlighter1_793_860_Open_Image" onclick="this.style.display='none'; Codehighlighter1_793_860_Open_Text.style.display='none'; Codehighlighter1_793_860_Closed_Image.style.display='inline'; Codehighlighter1_793_860_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_793_860_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_793_860_Closed_Text.style.display='none'; Codehighlighter1_793_860_Open_Image.style.display='inline'; Codehighlighter1_793_860_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_793_860_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_793_860_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">s1.Empty())<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            s2.Push(s1.Pop());<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> s2.Pop();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div></font>
<img src ="http://www.cppblog.com/Winux32/aggbug/15678.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Winux32/" target="_blank">Charles</a> 2006-11-26 18:45 <a href="http://www.cppblog.com/Winux32/archive/2006/11/26/15678.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>检测补码表示</title><link>http://www.cppblog.com/Winux32/archive/2006/11/24/15623.html</link><dc:creator>Charles</dc:creator><author>Charles</author><pubDate>Fri, 24 Nov 2006 05:54:00 GMT</pubDate><guid>http://www.cppblog.com/Winux32/archive/2006/11/24/15623.html</guid><wfw:comment>http://www.cppblog.com/Winux32/comments/15623.html</wfw:comment><comments>http://www.cppblog.com/Winux32/archive/2006/11/24/15623.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Winux32/comments/commentRss/15623.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Winux32/services/trackbacks/15623.html</trackback:ping><description><![CDATA[
		<font face="Verdana" color="#0000ff" size="2">检测底层数据表示是Two Complement还是One Complement<br /><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"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> CheckComplement()<br /><img id="Codehighlighter1_22_193_Open_Image" onclick="this.style.display='none'; Codehighlighter1_22_193_Open_Text.style.display='none'; Codehighlighter1_22_193_Closed_Image.style.display='inline'; Codehighlighter1_22_193_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_22_193_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_22_193_Closed_Text.style.display='none'; Codehighlighter1_22_193_Open_Image.style.display='inline'; Codehighlighter1_22_193_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_22_193_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_22_193_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    union<br /><img id="Codehighlighter1_32_71_Open_Image" onclick="this.style.display='none'; Codehighlighter1_32_71_Open_Text.style.display='none'; Codehighlighter1_32_71_Closed_Image.style.display='inline'; Codehighlighter1_32_71_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_32_71_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_32_71_Closed_Text.style.display='none'; Codehighlighter1_32_71_Open_Image.style.display='inline'; Codehighlighter1_32_71_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_32_71_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_32_71_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        unsigned </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> ui;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        signed </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> si;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000">uComplementChecker;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    uComplementChecker.si </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    unsigned </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> ui </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> (uComplementChecker.ui </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> ui) </span><span style="COLOR: #000000">?</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">2</span><span style="COLOR: #000000"> : </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div></font>
		<br />
		<font face="Verdana" color="#0000ff" size="2">还有一种，可移植性差一点<br /><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"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> if 2 return true, else false</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000"> CheckComplement2()<br /><img id="Codehighlighter1_56_100_Open_Image" onclick="this.style.display='none'; Codehighlighter1_56_100_Open_Text.style.display='none'; Codehighlighter1_56_100_Closed_Image.style.display='inline'; Codehighlighter1_56_100_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_56_100_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_56_100_Closed_Text.style.display='none'; Codehighlighter1_56_100_Open_Image.style.display='inline'; Codehighlighter1_56_100_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_56_100_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_56_100_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    signed </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> i </span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div></font>
<img src ="http://www.cppblog.com/Winux32/aggbug/15623.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Winux32/" target="_blank">Charles</a> 2006-11-24 13:54 <a href="http://www.cppblog.com/Winux32/archive/2006/11/24/15623.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>字节顺序检测</title><link>http://www.cppblog.com/Winux32/archive/2006/11/24/15621.html</link><dc:creator>Charles</dc:creator><author>Charles</author><pubDate>Fri, 24 Nov 2006 05:51:00 GMT</pubDate><guid>http://www.cppblog.com/Winux32/archive/2006/11/24/15621.html</guid><wfw:comment>http://www.cppblog.com/Winux32/comments/15621.html</wfw:comment><comments>http://www.cppblog.com/Winux32/archive/2006/11/24/15621.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Winux32/comments/commentRss/15621.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Winux32/services/trackbacks/15621.html</trackback:ping><description><![CDATA[
		<p>
				<font face="Verdana" color="#0000ff" size="2">多字节数据表示顺序问题。Big-Endian and Little-Endian说法来源于Jonathan Swift的作品&lt;Gulliver's Travels&gt;(《格列佛游记》), 小人国的居民争吵鸡蛋应该从大端打开还是从小端打开，作者其实是在模仿当时在天主教徒与新教徒之间正在进行的关于各自教义的争吵。<br />Intel的CPU采用小端表示法，如图<br /><img height="327" alt="ByteOrder.JPG" src="http://www.cppblog.com/images/cppblog_com/winux32/Platform/ByteOrder.JPG" width="763" border="0" /><br /><br /></font>
		</p>
		<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">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> CheckEndian()<br /><img id="Codehighlighter1_18_149_Open_Image" onclick="this.style.display='none'; Codehighlighter1_18_149_Open_Text.style.display='none'; Codehighlighter1_18_149_Closed_Image.style.display='inline'; Codehighlighter1_18_149_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_18_149_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_18_149_Closed_Text.style.display='none'; Codehighlighter1_18_149_Open_Image.style.display='inline'; Codehighlighter1_18_149_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_18_149_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_18_149_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    union<br /><img id="Codehighlighter1_28_66_Open_Image" onclick="this.style.display='none'; Codehighlighter1_28_66_Open_Text.style.display='none'; Codehighlighter1_28_66_Closed_Image.style.display='inline'; Codehighlighter1_28_66_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_28_66_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_28_66_Closed_Text.style.display='none'; Codehighlighter1_28_66_Open_Image.style.display='inline'; Codehighlighter1_28_66_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_28_66_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_28_66_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">int</span>
								<span style="COLOR: #000000"> iFourBytes;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">char</span>
								<span style="COLOR: #000000"> cOneByte;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">uEndianChecker;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    uEndianChecker.iFourBytes </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> uEndianChecker.cOneByte;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
<img src ="http://www.cppblog.com/Winux32/aggbug/15621.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Winux32/" target="_blank">Charles</a> 2006-11-24 13:51 <a href="http://www.cppblog.com/Winux32/archive/2006/11/24/15621.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>检查char是否有符号</title><link>http://www.cppblog.com/Winux32/archive/2006/11/24/15620.html</link><dc:creator>Charles</dc:creator><author>Charles</author><pubDate>Fri, 24 Nov 2006 05:41:00 GMT</pubDate><guid>http://www.cppblog.com/Winux32/archive/2006/11/24/15620.html</guid><wfw:comment>http://www.cppblog.com/Winux32/comments/15620.html</wfw:comment><comments>http://www.cppblog.com/Winux32/archive/2006/11/24/15620.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Winux32/comments/commentRss/15620.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Winux32/services/trackbacks/15620.html</trackback:ping><description><![CDATA[
		<p>
				<font face="Verdana" color="#0000ff" size="2">我们知道char型的整型值的符号随不同编译器实现而不同。如何测试呢<br /></font>
		</p>
		<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">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> CheckChar()<br /><img id="Codehighlighter1_16_153_Open_Image" onclick="this.style.display='none'; Codehighlighter1_16_153_Open_Text.style.display='none'; Codehighlighter1_16_153_Closed_Image.style.display='inline'; Codehighlighter1_16_153_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_16_153_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_16_153_Closed_Text.style.display='none'; Codehighlighter1_16_153_Open_Image.style.display='inline'; Codehighlighter1_16_153_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_16_153_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_16_153_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    union<br /><img id="Codehighlighter1_26_77_Open_Image" onclick="this.style.display='none'; Codehighlighter1_26_77_Open_Text.style.display='none'; Codehighlighter1_26_77_Closed_Image.style.display='inline'; Codehighlighter1_26_77_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_26_77_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_26_77_Closed_Text.style.display='none'; Codehighlighter1_26_77_Open_Image.style.display='inline'; Codehighlighter1_26_77_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_26_77_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_26_77_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">char</span>
								<span style="COLOR: #000000"> c;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        unsigned </span>
								<span style="COLOR: #0000ff">char</span>
								<span style="COLOR: #000000"> uc;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        signed </span>
								<span style="COLOR: #0000ff">char</span>
								<span style="COLOR: #000000"> sc;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">uCharChecker;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    uCharChecker.sc </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> uCharChecker.c </span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">?</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000"> : </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
<img src ="http://www.cppblog.com/Winux32/aggbug/15620.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Winux32/" target="_blank">Charles</a> 2006-11-24 13:41 <a href="http://www.cppblog.com/Winux32/archive/2006/11/24/15620.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>寻找最长递增子序列</title><link>http://www.cppblog.com/Winux32/archive/2006/11/22/15549.html</link><dc:creator>Charles</dc:creator><author>Charles</author><pubDate>Wed, 22 Nov 2006 09:50:00 GMT</pubDate><guid>http://www.cppblog.com/Winux32/archive/2006/11/22/15549.html</guid><wfw:comment>http://www.cppblog.com/Winux32/comments/15549.html</wfw:comment><comments>http://www.cppblog.com/Winux32/archive/2006/11/22/15549.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/Winux32/comments/commentRss/15549.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Winux32/services/trackbacks/15549.html</trackback:ping><description><![CDATA[
		<font color="#0000ff">
				<font face="Verdana" size="2">注意，不一定连续递增<br /></font>
				<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">
						<font face="Verdana">
								<font size="2">
										<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
										<span style="COLOR: #000000">template</span>
										<span style="COLOR: #000000">&lt;</span>
										<span style="COLOR: #0000ff">class</span>
										<span style="COLOR: #000000"> T</span>
										<span style="COLOR: #000000">&gt;</span>
								</font>
						</font>
						<font face="Verdana">
								<font size="2">
										<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
										<span style="COLOR: #0000ff">int</span>
										<span style="COLOR: #000000"> FindLIS(T </span>
										<span style="COLOR: #000000">*</span>
										<span style="COLOR: #000000">arr, </span>
										<span style="COLOR: #0000ff">int</span>
										<span style="COLOR: #000000"> len, T </span>
										<span style="COLOR: #000000">*&amp;</span>
								</font>
						</font>
						<font face="Verdana">
								<font size="2">
										<span style="COLOR: #000000">result)<br /><img id="Codehighlighter1_60_921_Open_Image" onclick="this.style.display='none'; Codehighlighter1_60_921_Open_Text.style.display='none'; Codehighlighter1_60_921_Closed_Image.style.display='inline'; Codehighlighter1_60_921_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_60_921_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_60_921_Closed_Text.style.display='none'; Codehighlighter1_60_921_Open_Image.style.display='inline'; Codehighlighter1_60_921_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
										<span id="Codehighlighter1_60_921_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
								</font>
						</font>
						<span id="Codehighlighter1_60_921_Open_Text">
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
												<span style="COLOR: #0000ff">int</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">*</span>
												<span style="COLOR: #000000">last </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #0000ff">new</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #0000ff">int</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">[len]();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
												<span style="COLOR: #0000ff">int</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">*</span>
												<span style="COLOR: #000000">track </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #0000ff">new</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #0000ff">int</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">[len]();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
												<span style="COLOR: #0000ff">int</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000"> left, right, mid;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
												<span style="COLOR: #0000ff">int</span>
												<span style="COLOR: #000000"> iCurrMaxLen </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">0</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
												<span style="COLOR: #0000ff">if</span>
												<span style="COLOR: #000000"> (len </span>
												<span style="COLOR: #000000">&lt;</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">1</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_182_211_Open_Image" onclick="this.style.display='none'; Codehighlighter1_182_211_Open_Text.style.display='none'; Codehighlighter1_182_211_Closed_Image.style.display='inline'; Codehighlighter1_182_211_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_182_211_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_182_211_Closed_Text.style.display='none'; Codehighlighter1_182_211_Open_Image.style.display='inline'; Codehighlighter1_182_211_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
												<span id="Codehighlighter1_182_211_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
														<img src="http://www.cppblog.com/images/dot.gif" />
												</span>
										</font>
								</font>
								<span id="Codehighlighter1_182_211_Open_Text">
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        result </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">0</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
														<span style="COLOR: #0000ff">return</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">0</span>
												</font>
										</font>
										<span style="COLOR: #000000">
												<font face="Verdana" size="2">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</font>
										</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<font face="Verdana" size="2">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    result </font>
								</span>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">0</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    last[</span>
												<span style="COLOR: #000000">0</span>
												<span style="COLOR: #000000">] </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">0</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
												<span style="COLOR: #0000ff">for</span>
												<span style="COLOR: #000000"> (</span>
												<span style="COLOR: #0000ff">int</span>
												<span style="COLOR: #000000"> i </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">1</span>
												<span style="COLOR: #000000">; i </span>
												<span style="COLOR: #000000">&lt;</span>
												<span style="COLOR: #000000"> len; i</span>
												<span style="COLOR: #000000">++</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">) <br /><img id="Codehighlighter1_275_687_Open_Image" onclick="this.style.display='none'; Codehighlighter1_275_687_Open_Text.style.display='none'; Codehighlighter1_275_687_Closed_Image.style.display='inline'; Codehighlighter1_275_687_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_275_687_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_275_687_Closed_Text.style.display='none'; Codehighlighter1_275_687_Open_Image.style.display='inline'; Codehighlighter1_275_687_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
												<span id="Codehighlighter1_275_687_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
														<img src="http://www.cppblog.com/images/dot.gif" />
												</span>
										</font>
								</font>
								<span id="Codehighlighter1_275_687_Open_Text">
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
														<span style="COLOR: #0000ff">if</span>
														<span style="COLOR: #000000"> (arr[last[iCurrMaxLen]] </span>
														<span style="COLOR: #000000">&lt;</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000"> arr[i])<br /><img id="Codehighlighter1_318_396_Open_Image" onclick="this.style.display='none'; Codehighlighter1_318_396_Open_Text.style.display='none'; Codehighlighter1_318_396_Closed_Image.style.display='inline'; Codehighlighter1_318_396_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_318_396_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_318_396_Closed_Text.style.display='none'; Codehighlighter1_318_396_Open_Image.style.display='inline'; Codehighlighter1_318_396_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
														<span id="Codehighlighter1_318_396_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
																<img src="http://www.cppblog.com/images/dot.gif" />
														</span>
												</font>
										</font>
										<span id="Codehighlighter1_318_396_Open_Text">
												<font face="Verdana">
														<font size="2">
																<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            track[i] </span>
																<span style="COLOR: #000000">=</span>
														</font>
												</font>
												<font face="Verdana">
														<font size="2">
																<span style="COLOR: #000000"> last[iCurrMaxLen];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            last[</span>
																<span style="COLOR: #000000">++</span>
																<span style="COLOR: #000000">iCurrMaxLen] </span>
																<span style="COLOR: #000000">=</span>
														</font>
												</font>
												<font face="Verdana">
														<font size="2">
																<span style="COLOR: #000000"> i;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
																<span style="COLOR: #0000ff">continue</span>
														</font>
												</font>
												<span style="COLOR: #000000">
														<font face="Verdana" size="2">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</font>
												</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<font face="Verdana" size="2">
														<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
														<br />
														<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        left </font>
										</span>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">0</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        right </span>
														<span style="COLOR: #000000">=</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000"> iCurrMaxLen;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
														<span style="COLOR: #0000ff">while</span>
														<span style="COLOR: #000000"> (left </span>
														<span style="COLOR: #000000">&lt;</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000"> right)<br /><img id="Codehighlighter1_459_552_Open_Image" onclick="this.style.display='none'; Codehighlighter1_459_552_Open_Text.style.display='none'; Codehighlighter1_459_552_Closed_Image.style.display='inline'; Codehighlighter1_459_552_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_459_552_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_459_552_Closed_Text.style.display='none'; Codehighlighter1_459_552_Open_Image.style.display='inline'; Codehighlighter1_459_552_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
														<span id="Codehighlighter1_459_552_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
																<img src="http://www.cppblog.com/images/dot.gif" />
														</span>
												</font>
										</font>
										<span id="Codehighlighter1_459_552_Open_Text">
												<font face="Verdana">
														<font size="2">
																<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            mid </span>
																<span style="COLOR: #000000">=</span>
																<span style="COLOR: #000000"> (left </span>
																<span style="COLOR: #000000">+</span>
																<span style="COLOR: #000000"> right) </span>
																<span style="COLOR: #000000">/</span>
																<span style="COLOR: #000000"> </span>
																<span style="COLOR: #000000">2</span>
														</font>
												</font>
												<font face="Verdana">
														<font size="2">
																<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            arr[last[mid]] </span>
																<span style="COLOR: #000000">&lt;</span>
																<span style="COLOR: #000000"> arr[i] </span>
																<span style="COLOR: #000000">?</span>
																<span style="COLOR: #000000"> left </span>
																<span style="COLOR: #000000">=</span>
																<span style="COLOR: #000000"> mid </span>
																<span style="COLOR: #000000">+</span>
																<span style="COLOR: #000000"> </span>
																<span style="COLOR: #000000">1</span>
																<span style="COLOR: #000000"> : right </span>
																<span style="COLOR: #000000">=</span>
														</font>
												</font>
												<span style="COLOR: #000000">
														<font face="Verdana" size="2"> mid;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</font>
												</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<font face="Verdana" size="2">
														<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
														<br />
														<img id="Codehighlighter1_561_581_Open_Image" onclick="this.style.display='none'; Codehighlighter1_561_581_Open_Text.style.display='none'; Codehighlighter1_561_581_Closed_Image.style.display='inline'; Codehighlighter1_561_581_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
														<img id="Codehighlighter1_561_581_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_561_581_Closed_Text.style.display='none'; Codehighlighter1_561_581_Open_Image.style.display='inline'; Codehighlighter1_561_581_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </font>
										</span>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #0000ff">if</span>
														<span style="COLOR: #000000"> (</span>
														<span id="Codehighlighter1_561_581_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span>
														<span id="Codehighlighter1_561_581_Open_Text">
																<span style="COLOR: #008000">/*</span>
																<span style="COLOR: #008000">left &lt;= right &amp;&amp; </span>
																<span style="COLOR: #008000">*/</span>
														</span>
														<span style="COLOR: #000000">arr[i] </span>
														<span style="COLOR: #000000">&lt;</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000"> arr[last[left]]) <br /><img id="Codehighlighter1_611_683_Open_Image" onclick="this.style.display='none'; Codehighlighter1_611_683_Open_Text.style.display='none'; Codehighlighter1_611_683_Closed_Image.style.display='inline'; Codehighlighter1_611_683_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_611_683_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_611_683_Closed_Text.style.display='none'; Codehighlighter1_611_683_Open_Image.style.display='inline'; Codehighlighter1_611_683_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
														<span id="Codehighlighter1_611_683_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
																<img src="http://www.cppblog.com/images/dot.gif" />
														</span>
												</font>
										</font>
										<span id="Codehighlighter1_611_683_Open_Text">
												<font face="Verdana">
														<font size="2">
																<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
																<span style="COLOR: #0000ff">if</span>
																<span style="COLOR: #000000"> (left </span>
																<span style="COLOR: #000000">&gt;</span>
																<span style="COLOR: #000000"> </span>
																<span style="COLOR: #000000">0</span>
														</font>
												</font>
												<font face="Verdana">
														<font size="2">
																<span style="COLOR: #000000">) <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                track[i] </span>
																<span style="COLOR: #000000">=</span>
																<span style="COLOR: #000000"> last[left </span>
																<span style="COLOR: #000000">-</span>
																<span style="COLOR: #000000"> </span>
																<span style="COLOR: #000000">1</span>
														</font>
												</font>
												<font face="Verdana">
														<font size="2">
																<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            last[left] </span>
																<span style="COLOR: #000000">=</span>
														</font>
												</font>
												<span style="COLOR: #000000">
														<font face="Verdana" size="2"> i;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</font>
												</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<font face="Verdana" size="2">
														<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
														<br />
														<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</font>
										</span>
								</span>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #008000">//</span>
												<span style="COLOR: #008000">for</span>
										</font>
								</font>
								<span style="COLOR: #008000">
										<br />
										<font face="Verdana" size="2">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
										</font>
								</span>
								<span style="COLOR: #000000">
										<br />
										<font face="Verdana" size="2">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </font>
								</span>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #0000ff">for</span>
												<span style="COLOR: #000000"> (left </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> iCurrMaxLen, right </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> last[iCurrMaxLen]; left </span>
												<span style="COLOR: #000000">&gt;=</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">0</span>
												<span style="COLOR: #000000">; left</span>
												<span style="COLOR: #000000">--</span>
												<span style="COLOR: #000000">, right </span>
												<span style="COLOR: #000000">=</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000"> track[right])<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        last[left] </span>
												<span style="COLOR: #000000">=</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000"> arr[right];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
												<span style="COLOR: #0000ff">if</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000"> (track)<br /><img id="Codehighlighter1_830_865_Open_Image" onclick="this.style.display='none'; Codehighlighter1_830_865_Open_Text.style.display='none'; Codehighlighter1_830_865_Closed_Image.style.display='inline'; Codehighlighter1_830_865_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_830_865_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_830_865_Closed_Text.style.display='none'; Codehighlighter1_830_865_Open_Image.style.display='inline'; Codehighlighter1_830_865_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
												<span id="Codehighlighter1_830_865_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
														<img src="http://www.cppblog.com/images/dot.gif" />
												</span>
										</font>
								</font>
								<span id="Codehighlighter1_830_865_Open_Text">
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        delete [] track;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        track </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">0</span>
												</font>
										</font>
										<span style="COLOR: #000000">
												<font face="Verdana" size="2">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</font>
										</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<font face="Verdana" size="2">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    result </font>
								</span>
								<span style="COLOR: #000000">
										<font face="Verdana" size="2">=</font>
								</span>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000"> last;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    last </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">0</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
												<span style="COLOR: #0000ff">return</span>
												<span style="COLOR: #000000"> iCurrMaxLen </span>
												<span style="COLOR: #000000">+</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">1</span>
										</font>
								</font>
								<span style="COLOR: #000000">
										<font face="Verdana" size="2">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</font>
								</span>
						</span>
				</div>
		</font>
		<font face="Verdana" color="#0000ff" size="2">稍微解释一下，last中存的是所有i长度子序列中last[i]最小的那个值。而track中记录它的前一个值。这样可以沿着track找回去。</font>
<img src ="http://www.cppblog.com/Winux32/aggbug/15549.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Winux32/" target="_blank">Charles</a> 2006-11-22 17:50 <a href="http://www.cppblog.com/Winux32/archive/2006/11/22/15549.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>计算最长递增子序列的长度</title><link>http://www.cppblog.com/Winux32/archive/2006/11/22/15548.html</link><dc:creator>Charles</dc:creator><author>Charles</author><pubDate>Wed, 22 Nov 2006 09:45:00 GMT</pubDate><guid>http://www.cppblog.com/Winux32/archive/2006/11/22/15548.html</guid><wfw:comment>http://www.cppblog.com/Winux32/comments/15548.html</wfw:comment><comments>http://www.cppblog.com/Winux32/archive/2006/11/22/15548.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Winux32/comments/commentRss/15548.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Winux32/services/trackbacks/15548.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">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">template</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> T</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> GetLISLen(T </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">arr, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> n)<br /><img id="Codehighlighter1_47_758_Open_Image" onclick="this.style.display='none'; Codehighlighter1_47_758_Open_Text.style.display='none'; Codehighlighter1_47_758_Closed_Image.style.display='inline'; Codehighlighter1_47_758_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_47_758_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_47_758_Closed_Text.style.display='none'; Codehighlighter1_47_758_Open_Image.style.display='inline'; Codehighlighter1_47_758_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_47_758_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_47_758_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (n </span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> iCurrMaxLen </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> left, right, mid;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000">last </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">new</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000">[n]();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    last[</span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">] </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> arr[</span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (</span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">; i </span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000"> n; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_199_533_Open_Image" onclick="this.style.display='none'; Codehighlighter1_199_533_Open_Text.style.display='none'; Codehighlighter1_199_533_Closed_Image.style.display='inline'; Codehighlighter1_199_533_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_199_533_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_199_533_Closed_Text.style.display='none'; Codehighlighter1_199_533_Open_Image.style.display='inline'; Codehighlighter1_199_533_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_199_533_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_199_533_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000"> (arr[i] </span>
								<span style="COLOR: #000000">&gt;=</span>
								<span style="COLOR: #000000"> last[iCurrMaxLen])<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            last[</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">iCurrMaxLen] </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> arr[i];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">else</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000"> (arr[i] </span>
								<span style="COLOR: #000000">&lt;</span>
								<span style="COLOR: #000000"> last[</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">])<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            last[</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">] </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> arr[i];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">else</span>
								<span style="COLOR: #000000">
										<br />
										<img id="Codehighlighter1_328_523_Open_Image" onclick="this.style.display='none'; Codehighlighter1_328_523_Open_Text.style.display='none'; Codehighlighter1_328_523_Closed_Image.style.display='inline'; Codehighlighter1_328_523_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
										<img id="Codehighlighter1_328_523_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_328_523_Closed_Text.style.display='none'; Codehighlighter1_328_523_Open_Image.style.display='inline'; Codehighlighter1_328_523_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_328_523_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_328_523_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            left </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            right </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> iCurrMaxLen;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">while</span>
										<span style="COLOR: #000000"> (left </span>
										<span style="COLOR: #000000">!=</span>
										<span style="COLOR: #000000"> right </span>
										<span style="COLOR: #000000">-</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_400_493_Open_Image" onclick="this.style.display='none'; Codehighlighter1_400_493_Open_Text.style.display='none'; Codehighlighter1_400_493_Closed_Image.style.display='inline'; Codehighlighter1_400_493_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_400_493_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_400_493_Closed_Text.style.display='none'; Codehighlighter1_400_493_Open_Image.style.display='inline'; Codehighlighter1_400_493_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
										<span id="Codehighlighter1_400_493_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_400_493_Open_Text">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                mid </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> (left </span>
												<span style="COLOR: #000000">+</span>
												<span style="COLOR: #000000"> right) </span>
												<span style="COLOR: #000000">/</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">2</span>
												<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                (last[mid] </span>
												<span style="COLOR: #000000">&lt;=</span>
												<span style="COLOR: #000000"> arr[i]) </span>
												<span style="COLOR: #000000">?</span>
												<span style="COLOR: #000000"> (left </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> mid) : (right </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> mid);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            last[right] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> arr[i];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">if</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">for</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (</span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">; i </span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000"> iCurrMaxLen </span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_585_682_Open_Image" onclick="this.style.display='none'; Codehighlighter1_585_682_Open_Text.style.display='none'; Codehighlighter1_585_682_Closed_Image.style.display='inline'; Codehighlighter1_585_682_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_585_682_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_585_682_Closed_Text.style.display='none'; Codehighlighter1_585_682_Open_Image.style.display='inline'; Codehighlighter1_585_682_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_585_682_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_585_682_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        printf(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">%d</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">, last[i]);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000"> (i </span>
								<span style="COLOR: #000000">!=</span>
								<span style="COLOR: #000000"> iCurrMaxLen)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            printf(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">\x20</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">else</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            printf(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">\n</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (last)<br /><img id="Codehighlighter1_697_730_Open_Image" onclick="this.style.display='none'; Codehighlighter1_697_730_Open_Text.style.display='none'; Codehighlighter1_697_730_Closed_Image.style.display='inline'; Codehighlighter1_697_730_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_697_730_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_697_730_Closed_Text.style.display='none'; Codehighlighter1_697_730_Open_Image.style.display='inline'; Codehighlighter1_697_730_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_697_730_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_697_730_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        delete [] last;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        last </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> iCurrMaxLen </span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
<img src ="http://www.cppblog.com/Winux32/aggbug/15548.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Winux32/" target="_blank">Charles</a> 2006-11-22 17:45 <a href="http://www.cppblog.com/Winux32/archive/2006/11/22/15548.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>打印所有递增子序列</title><link>http://www.cppblog.com/Winux32/archive/2006/11/22/15547.html</link><dc:creator>Charles</dc:creator><author>Charles</author><pubDate>Wed, 22 Nov 2006 09:44:00 GMT</pubDate><guid>http://www.cppblog.com/Winux32/archive/2006/11/22/15547.html</guid><wfw:comment>http://www.cppblog.com/Winux32/comments/15547.html</wfw:comment><comments>http://www.cppblog.com/Winux32/archive/2006/11/22/15547.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Winux32/comments/commentRss/15547.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Winux32/services/trackbacks/15547.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">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">cstdio</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />template </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> T</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> OutputAllConIncSubseq(</span>
				<span style="COLOR: #0000ff">const</span>
				<span style="COLOR: #000000"> T </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">arr, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> n)<br /><img id="Codehighlighter1_85_341_Open_Image" onclick="this.style.display='none'; Codehighlighter1_85_341_Open_Text.style.display='none'; Codehighlighter1_85_341_Closed_Image.style.display='inline'; Codehighlighter1_85_341_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_85_341_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_85_341_Closed_Text.style.display='none'; Codehighlighter1_85_341_Open_Image.style.display='inline'; Codehighlighter1_85_341_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_85_341_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_85_341_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> start, end, i;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">for</span>
						<span style="COLOR: #000000"> (start </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">; start </span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000"> n; start</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_146_339_Open_Image" onclick="this.style.display='none'; Codehighlighter1_146_339_Open_Text.style.display='none'; Codehighlighter1_146_339_Closed_Image.style.display='inline'; Codehighlighter1_146_339_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_146_339_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_146_339_Closed_Text.style.display='none'; Codehighlighter1_146_339_Open_Image.style.display='inline'; Codehighlighter1_146_339_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_146_339_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_146_339_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">NUL is always less than any other char</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000"> (end </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> start </span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">; arr[end] </span>
								<span style="COLOR: #000000">&gt;</span>
								<span style="COLOR: #000000"> arr[end </span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">]; end</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_249_336_Open_Image" onclick="this.style.display='none'; Codehighlighter1_249_336_Open_Text.style.display='none'; Codehighlighter1_249_336_Closed_Image.style.display='inline'; Codehighlighter1_249_336_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_249_336_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_249_336_Closed_Text.style.display='none'; Codehighlighter1_249_336_Open_Image.style.display='inline'; Codehighlighter1_249_336_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_249_336_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_249_336_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">for</span>
										<span style="COLOR: #000000"> (i </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> start; i </span>
										<span style="COLOR: #000000">&lt;</span>
										<span style="COLOR: #000000"> end </span>
										<span style="COLOR: #000000">+</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">; i</span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000"> )<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                printf(</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">%d </span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">, arr[i]);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            printf(</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">\n</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
<img src ="http://www.cppblog.com/Winux32/aggbug/15547.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Winux32/" target="_blank">Charles</a> 2006-11-22 17:44 <a href="http://www.cppblog.com/Winux32/archive/2006/11/22/15547.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>寻找最长连续递增子序列</title><link>http://www.cppblog.com/Winux32/archive/2006/11/22/15534.html</link><dc:creator>Charles</dc:creator><author>Charles</author><pubDate>Wed, 22 Nov 2006 04:24:00 GMT</pubDate><guid>http://www.cppblog.com/Winux32/archive/2006/11/22/15534.html</guid><wfw:comment>http://www.cppblog.com/Winux32/comments/15534.html</wfw:comment><comments>http://www.cppblog.com/Winux32/archive/2006/11/22/15534.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/Winux32/comments/commentRss/15534.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Winux32/services/trackbacks/15534.html</trackback:ping><description><![CDATA[
		<font color="#0000ff">
				<font face="Verdana" size="2">注意是连续递增<br />比如，"12345367889abcdefghij123" -&gt; "abcdefghij"<br /></font>
				<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">
						<font face="Verdana">
								<font size="2">
										<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
										<span style="COLOR: #000000">template </span>
										<span style="COLOR: #000000">&lt;</span>
										<span style="COLOR: #0000ff">class</span>
										<span style="COLOR: #000000"> T</span>
										<span style="COLOR: #000000">&gt;</span>
								</font>
						</font>
						<span style="COLOR: #000000">
								<br />
								<font face="Verdana" size="2">
										<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
								</font>
						</span>
						<font face="Verdana">
								<font size="2">
										<span style="COLOR: #0000ff">int</span>
										<span style="COLOR: #000000"> FindLongestConIncSubseq(</span>
										<span style="COLOR: #0000ff">const</span>
										<span style="COLOR: #000000"> T </span>
										<span style="COLOR: #000000">*</span>
										<span style="COLOR: #000000">arr, </span>
										<span style="COLOR: #0000ff">int</span>
										<span style="COLOR: #000000"> n, </span>
										<span style="COLOR: #0000ff">int</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">*</span>
								</font>
						</font>
						<font face="Verdana">
								<font size="2">
										<span style="COLOR: #000000">pos)<br /><img id="Codehighlighter1_78_470_Open_Image" onclick="this.style.display='none'; Codehighlighter1_78_470_Open_Text.style.display='none'; Codehighlighter1_78_470_Closed_Image.style.display='inline'; Codehighlighter1_78_470_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_78_470_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_78_470_Closed_Text.style.display='none'; Codehighlighter1_78_470_Open_Image.style.display='inline'; Codehighlighter1_78_470_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
										<span id="Codehighlighter1_78_470_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
								</font>
						</font>
						<span id="Codehighlighter1_78_470_Open_Text">
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
												<span style="COLOR: #0000ff">int</span>
												<span style="COLOR: #000000"> start </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">0</span>
												<span style="COLOR: #000000">, end </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">1</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
												<span style="COLOR: #0000ff">int</span>
												<span style="COLOR: #000000"> iMaxLen </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">1</span>
												<span style="COLOR: #000000">, iCurrLen </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">1</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
												<span style="COLOR: #0000ff">for</span>
												<span style="COLOR: #000000"> (end </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">1</span>
												<span style="COLOR: #000000">; end </span>
												<span style="COLOR: #000000">&lt;</span>
												<span style="COLOR: #000000"> n; end</span>
												<span style="COLOR: #000000">++</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_170_351_Open_Image" onclick="this.style.display='none'; Codehighlighter1_170_351_Open_Text.style.display='none'; Codehighlighter1_170_351_Closed_Image.style.display='inline'; Codehighlighter1_170_351_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_170_351_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_170_351_Closed_Text.style.display='none'; Codehighlighter1_170_351_Open_Image.style.display='inline'; Codehighlighter1_170_351_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
												<span id="Codehighlighter1_170_351_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
														<img src="http://www.cppblog.com/images/dot.gif" />
												</span>
										</font>
								</font>
								<span id="Codehighlighter1_170_351_Open_Text">
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
														<span style="COLOR: #0000ff">if</span>
														<span style="COLOR: #000000"> (arr[end] </span>
														<span style="COLOR: #000000">&gt;=</span>
														<span style="COLOR: #000000"> arr[end </span>
														<span style="COLOR: #000000">-</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">1</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000">])<br /><img id="Codehighlighter1_206_225_Open_Image" onclick="this.style.display='none'; Codehighlighter1_206_225_Open_Text.style.display='none'; Codehighlighter1_206_225_Closed_Image.style.display='inline'; Codehighlighter1_206_225_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_206_225_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_206_225_Closed_Text.style.display='none'; Codehighlighter1_206_225_Open_Image.style.display='inline'; Codehighlighter1_206_225_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
														<span id="Codehighlighter1_206_225_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
																<img src="http://www.cppblog.com/images/dot.gif" />
														</span>
												</font>
										</font>
										<span id="Codehighlighter1_206_225_Open_Text">
												<font face="Verdana">
														<font size="2">
																<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            iCurrLen</span>
																<span style="COLOR: #000000">++</span>
														</font>
												</font>
												<span style="COLOR: #000000">
														<font face="Verdana" size="2">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</font>
												</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<font face="Verdana" size="2">
														<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </font>
										</span>
										<span style="COLOR: #0000ff">
												<font face="Verdana" size="2">else</font>
										</span>
										<span style="COLOR: #000000">
												<br />
												<font face="Verdana" size="2">
														<img id="Codehighlighter1_236_346_Open_Image" onclick="this.style.display='none'; Codehighlighter1_236_346_Open_Text.style.display='none'; Codehighlighter1_236_346_Closed_Image.style.display='inline'; Codehighlighter1_236_346_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
														<img id="Codehighlighter1_236_346_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_236_346_Closed_Text.style.display='none'; Codehighlighter1_236_346_Open_Image.style.display='inline'; Codehighlighter1_236_346_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </font>
										</span>
										<span id="Codehighlighter1_236_346_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<font face="Verdana" size="2">
														<img src="http://www.cppblog.com/images/dot.gif" />
												</font>
										</span>
										<span id="Codehighlighter1_236_346_Open_Text">
												<font face="Verdana">
														<font size="2">
																<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
																<span style="COLOR: #0000ff">if</span>
																<span style="COLOR: #000000"> (iCurrLen </span>
																<span style="COLOR: #000000">&gt;</span>
														</font>
												</font>
												<font face="Verdana">
														<font size="2">
																<span style="COLOR: #000000"> iMaxLen)<br /><img id="Codehighlighter1_268_324_Open_Image" onclick="this.style.display='none'; Codehighlighter1_268_324_Open_Text.style.display='none'; Codehighlighter1_268_324_Closed_Image.style.display='inline'; Codehighlighter1_268_324_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_268_324_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_268_324_Closed_Text.style.display='none'; Codehighlighter1_268_324_Open_Image.style.display='inline'; Codehighlighter1_268_324_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
																<span id="Codehighlighter1_268_324_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
																		<img src="http://www.cppblog.com/images/dot.gif" />
																</span>
														</font>
												</font>
												<span id="Codehighlighter1_268_324_Open_Text">
														<font face="Verdana">
																<font size="2">
																		<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                iMaxLen </span>
																		<span style="COLOR: #000000">=</span>
																</font>
														</font>
														<font face="Verdana">
																<font size="2">
																		<span style="COLOR: #000000"> iCurrLen;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                start </span>
																		<span style="COLOR: #000000">=</span>
																		<span style="COLOR: #000000"> end </span>
																		<span style="COLOR: #000000">-</span>
																</font>
														</font>
														<span style="COLOR: #000000">
																<font face="Verdana" size="2"> iMaxLen;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</font>
														</span>
												</span>
												<span style="COLOR: #000000">
														<br />
														<font face="Verdana" size="2">
																<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
																<br />
																<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            iCurrLen </font>
												</span>
												<font face="Verdana">
														<font size="2">
																<span style="COLOR: #000000">=</span>
																<span style="COLOR: #000000"> </span>
																<span style="COLOR: #000000">1</span>
														</font>
												</font>
												<span style="COLOR: #000000">
														<font face="Verdana" size="2">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</font>
												</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<font face="Verdana" size="2">
														<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</font>
										</span>
								</span>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #008000">//</span>
												<span style="COLOR: #008000">for</span>
										</font>
								</font>
								<span style="COLOR: #008000">
										<br />
										<font face="Verdana" size="2">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
										</font>
								</span>
								<span style="COLOR: #000000">
										<br />
										<font face="Verdana" size="2">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </font>
								</span>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #0000ff">if</span>
												<span style="COLOR: #000000"> (iCurrLen </span>
												<span style="COLOR: #000000">&gt;</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000"> iMaxLen)<br /><img id="Codehighlighter1_385_435_Open_Image" onclick="this.style.display='none'; Codehighlighter1_385_435_Open_Text.style.display='none'; Codehighlighter1_385_435_Closed_Image.style.display='inline'; Codehighlighter1_385_435_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_385_435_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_385_435_Closed_Text.style.display='none'; Codehighlighter1_385_435_Open_Image.style.display='inline'; Codehighlighter1_385_435_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
												<span id="Codehighlighter1_385_435_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
														<img src="http://www.cppblog.com/images/dot.gif" />
												</span>
										</font>
								</font>
								<span id="Codehighlighter1_385_435_Open_Text">
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        iMaxLen </span>
														<span style="COLOR: #000000">=</span>
												</font>
										</font>
										<font face="Verdana">
												<font size="2">
														<span style="COLOR: #000000"> iCurrLen;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        start </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> end </span>
														<span style="COLOR: #000000">-</span>
												</font>
										</font>
										<span style="COLOR: #000000">
												<font face="Verdana" size="2"> iMaxLen;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</font>
										</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<font face="Verdana" size="2">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </font>
								</span>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000">*</span>
												<span style="COLOR: #000000">pos </span>
												<span style="COLOR: #000000">=</span>
										</font>
								</font>
								<font face="Verdana">
										<font size="2">
												<span style="COLOR: #000000"> start;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
												<span style="COLOR: #0000ff">return</span>
										</font>
								</font>
								<span style="COLOR: #000000">
										<font face="Verdana" size="2"> iMaxLen;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</font>
								</span>
						</span>
				</div>
		</font>
		<font face="Verdana" color="#0000ff" size="2">还有一种比较难的就是非连续递增子序列，这个得用到<font color="#ff0000"><strike>回溯</strike><font color="#0000ff">薄记</font></font>，下篇贴</font>
<img src ="http://www.cppblog.com/Winux32/aggbug/15534.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Winux32/" target="_blank">Charles</a> 2006-11-22 12:24 <a href="http://www.cppblog.com/Winux32/archive/2006/11/22/15534.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>字符串原地压缩</title><link>http://www.cppblog.com/Winux32/archive/2006/11/22/15533.html</link><dc:creator>Charles</dc:creator><author>Charles</author><pubDate>Wed, 22 Nov 2006 04:19:00 GMT</pubDate><guid>http://www.cppblog.com/Winux32/archive/2006/11/22/15533.html</guid><wfw:comment>http://www.cppblog.com/Winux32/comments/15533.html</wfw:comment><comments>http://www.cppblog.com/Winux32/archive/2006/11/22/15533.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/Winux32/comments/commentRss/15533.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Winux32/services/trackbacks/15533.html</trackback:ping><description><![CDATA[
		<font face="Verdana" color="#0000ff" size="2">"aaaaaabbbbccccc" -&gt; "a6b4c5"<br /><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"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> CompressStrInPlace(</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> str)<br /><img id="Codehighlighter1_35_536_Open_Image" onclick="this.style.display='none'; Codehighlighter1_35_536_Open_Text.style.display='none'; Codehighlighter1_35_536_Closed_Image.style.display='inline'; Codehighlighter1_35_536_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_35_536_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_35_536_Closed_Text.style.display='none'; Codehighlighter1_35_536_Open_Image.style.display='inline'; Codehighlighter1_35_536_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_35_536_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_35_536_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> ((</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> str) </span><span style="COLOR: #000000">||</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">\0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">str))<br /><img id="Codehighlighter1_74_88_Open_Image" onclick="this.style.display='none'; Codehighlighter1_74_88_Open_Text.style.display='none'; Codehighlighter1_74_88_Closed_Image.style.display='inline'; Codehighlighter1_74_88_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_74_88_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_74_88_Closed_Text.style.display='none'; Codehighlighter1_74_88_Open_Image.style.display='inline'; Codehighlighter1_74_88_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_74_88_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_74_88_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> ;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> p </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> str </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000"> temp[</span><span style="COLOR: #000000">11</span><span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> rep </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> sNum </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">p </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">\0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)<br /><img id="Codehighlighter1_181_507_Open_Image" onclick="this.style.display='none'; Codehighlighter1_181_507_Open_Text.style.display='none'; Codehighlighter1_181_507_Closed_Image.style.display='inline'; Codehighlighter1_181_507_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_181_507_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_181_507_Closed_Text.style.display='none'; Codehighlighter1_181_507_Open_Image.style.display='inline'; Codehighlighter1_181_507_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_181_507_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_181_507_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">str </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">p)<br /><img id="Codehighlighter1_203_227_Open_Image" onclick="this.style.display='none'; Codehighlighter1_203_227_Open_Text.style.display='none'; Codehighlighter1_203_227_Closed_Image.style.display='inline'; Codehighlighter1_203_227_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_203_227_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_203_227_Closed_Text.style.display='none'; Codehighlighter1_203_227_Open_Image.style.display='inline'; Codehighlighter1_203_227_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span id="Codehighlighter1_203_227_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_203_227_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">str) </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">p</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br /><img id="Codehighlighter1_238_494_Open_Image" onclick="this.style.display='none'; Codehighlighter1_238_494_Open_Text.style.display='none'; Codehighlighter1_238_494_Closed_Image.style.display='inline'; Codehighlighter1_238_494_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_238_494_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_238_494_Closed_Text.style.display='none'; Codehighlighter1_238_494_Open_Image.style.display='inline'; Codehighlighter1_238_494_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span id="Codehighlighter1_238_494_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_238_494_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">p </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">str)<br /><img id="Codehighlighter1_265_290_Open_Image" onclick="this.style.display='none'; Codehighlighter1_265_290_Open_Text.style.display='none'; Codehighlighter1_265_290_Closed_Image.style.display='inline'; Codehighlighter1_265_290_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_265_290_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_265_290_Closed_Text.style.display='none'; Codehighlighter1_265_290_Open_Image.style.display='inline'; Codehighlighter1_265_290_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span><span id="Codehighlighter1_265_290_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_265_290_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">rep;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">p;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (rep </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">)<br /><img id="Codehighlighter1_313_351_Open_Image" onclick="this.style.display='none'; Codehighlighter1_313_351_Open_Text.style.display='none'; Codehighlighter1_313_351_Closed_Image.style.display='inline'; Codehighlighter1_313_351_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_313_351_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_313_351_Closed_Text.style.display='none'; Codehighlighter1_313_351_Open_Image.style.display='inline'; Codehighlighter1_313_351_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span><span id="Codehighlighter1_313_351_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_313_351_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">str) </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> rep </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">; </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 30h</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" /></span><span style="COLOR: #000000">            }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br /><img id="Codehighlighter1_364_476_Open_Image" onclick="this.style.display='none'; Codehighlighter1_364_476_Open_Text.style.display='none'; Codehighlighter1_364_476_Closed_Image.style.display='inline'; Codehighlighter1_364_476_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_364_476_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_364_476_Closed_Text.style.display='none'; Codehighlighter1_364_476_Open_Image.style.display='inline'; Codehighlighter1_364_476_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span><span id="Codehighlighter1_364_476_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_364_476_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> sNum </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> itoa(rep, temp, </span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> ((</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">str) </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">sNum</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">) </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">\0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)<br /><img id="Codehighlighter1_452_459_Open_Image" onclick="this.style.display='none'; Codehighlighter1_452_459_Open_Text.style.display='none'; Codehighlighter1_452_459_Closed_Image.style.display='inline'; Codehighlighter1_452_459_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_452_459_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_452_459_Closed_Text.style.display='none'; Codehighlighter1_452_459_Open_Image.style.display='inline'; Codehighlighter1_452_459_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />                    </span><span id="Codehighlighter1_452_459_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span><span id="Codehighlighter1_452_459_Open_Text"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">null</span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">str;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            rep </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">if-else</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">while</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">str) </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">\0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div></font>
<img src ="http://www.cppblog.com/Winux32/aggbug/15533.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Winux32/" target="_blank">Charles</a> 2006-11-22 12:19 <a href="http://www.cppblog.com/Winux32/archive/2006/11/22/15533.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>7进制转3进制</title><link>http://www.cppblog.com/Winux32/archive/2006/11/21/15502.html</link><dc:creator>Charles</dc:creator><author>Charles</author><pubDate>Tue, 21 Nov 2006 03:08:00 GMT</pubDate><guid>http://www.cppblog.com/Winux32/archive/2006/11/21/15502.html</guid><wfw:comment>http://www.cppblog.com/Winux32/comments/15502.html</wfw:comment><comments>http://www.cppblog.com/Winux32/archive/2006/11/21/15502.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Winux32/comments/commentRss/15502.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Winux32/services/trackbacks/15502.html</trackback:ping><description><![CDATA[
		<font face="Verdana" color="#0000ff" size="2">又是一道MS的题，把7进制数转换成3进制数。<br /><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"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">climits</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000"> ConvertBase723(</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">src, </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">dst, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> len)<br /><img id="Codehighlighter1_76_623_Open_Image" onclick="this.style.display='none'; Codehighlighter1_76_623_Open_Text.style.display='none'; Codehighlighter1_76_623_Closed_Image.style.display='inline'; Codehighlighter1_76_623_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_76_623_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_76_623_Closed_Text.style.display='none'; Codehighlighter1_76_623_Open_Image.style.display='inline'; Codehighlighter1_76_623_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_76_623_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_76_623_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> digit;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> value </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> start </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">, end </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; src[i] </span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000"> src[i] </span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">6</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">; i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br /><img id="Codehighlighter1_187_317_Open_Image" onclick="this.style.display='none'; Codehighlighter1_187_317_Open_Text.style.display='none'; Codehighlighter1_187_317_Closed_Image.style.display='inline'; Codehighlighter1_187_317_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_187_317_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_187_317_Closed_Text.style.display='none'; Codehighlighter1_187_317_Open_Image.style.display='inline'; Codehighlighter1_187_317_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_187_317_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_187_317_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (value </span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000"> (INT_MAX </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000"> (digit </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> src[i] </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)) </span><span style="COLOR: #000000">/</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">7</span><span style="COLOR: #000000">)<br /><img id="Codehighlighter1_246_281_Open_Image" onclick="this.style.display='none'; Codehighlighter1_246_281_Open_Text.style.display='none'; Codehighlighter1_246_281_Closed_Image.style.display='inline'; Codehighlighter1_246_281_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_246_281_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_246_281_Closed_Text.style.display='none'; Codehighlighter1_246_281_Open_Image.style.display='inline'; Codehighlighter1_246_281_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span id="Codehighlighter1_246_281_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_246_281_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            value </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">7</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> value </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> digit;    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br /><img id="Codehighlighter1_293_314_Open_Image" onclick="this.style.display='none'; Codehighlighter1_293_314_Open_Text.style.display='none'; Codehighlighter1_293_314_Closed_Image.style.display='inline'; Codehighlighter1_293_314_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_293_314_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_293_314_Closed_Text.style.display='none'; Codehighlighter1_293_314_Open_Image.style.display='inline'; Codehighlighter1_293_314_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span id="Codehighlighter1_293_314_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_293_314_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">for</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #000000">    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">do</span><span style="COLOR: #000000"> <br /><img id="Codehighlighter1_332_391_Open_Image" onclick="this.style.display='none'; Codehighlighter1_332_391_Open_Text.style.display='none'; Codehighlighter1_332_391_Closed_Image.style.display='inline'; Codehighlighter1_332_391_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_332_391_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_332_391_Closed_Text.style.display='none'; Codehighlighter1_332_391_Open_Image.style.display='inline'; Codehighlighter1_332_391_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_332_391_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_332_391_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        dst[end</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> value </span><span style="COLOR: #000000">%</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">3</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        value </span><span style="COLOR: #000000">/=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        len</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(value </span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000"> (len </span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (len </span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br /><img id="Codehighlighter1_438_457_Open_Image" onclick="this.style.display='none'; Codehighlighter1_438_457_Open_Text.style.display='none'; Codehighlighter1_438_457_Closed_Image.style.display='inline'; Codehighlighter1_438_457_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_438_457_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_438_457_Closed_Text.style.display='none'; Codehighlighter1_438_457_Open_Image.style.display='inline'; Codehighlighter1_438_457_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_438_457_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_438_457_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    dst[end</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">\0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> (start </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> end)<br /><img id="Codehighlighter1_504_606_Open_Image" onclick="this.style.display='none'; Codehighlighter1_504_606_Open_Text.style.display='none'; Codehighlighter1_504_606_Closed_Image.style.display='inline'; Codehighlighter1_504_606_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_504_606_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_504_606_Closed_Text.style.display='none'; Codehighlighter1_504_606_Open_Image.style.display='inline'; Codehighlighter1_504_606_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_504_606_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_504_606_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        dst[start] </span><span style="COLOR: #000000">^=</span><span style="COLOR: #000000"> dst[end];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        dst[end] </span><span style="COLOR: #000000">^=</span><span style="COLOR: #000000"> dst[start];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        dst[start] </span><span style="COLOR: #000000">^=</span><span style="COLOR: #000000"> dst[end];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        start</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        end</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div></font>
<img src ="http://www.cppblog.com/Winux32/aggbug/15502.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Winux32/" target="_blank">Charles</a> 2006-11-21 11:08 <a href="http://www.cppblog.com/Winux32/archive/2006/11/21/15502.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>数单词数</title><link>http://www.cppblog.com/Winux32/archive/2006/11/21/15501.html</link><dc:creator>Charles</dc:creator><author>Charles</author><pubDate>Tue, 21 Nov 2006 03:06:00 GMT</pubDate><guid>http://www.cppblog.com/Winux32/archive/2006/11/21/15501.html</guid><wfw:comment>http://www.cppblog.com/Winux32/comments/15501.html</wfw:comment><comments>http://www.cppblog.com/Winux32/archive/2006/11/21/15501.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/Winux32/comments/commentRss/15501.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Winux32/services/trackbacks/15501.html</trackback:ping><description><![CDATA[
		<font face="Verdana" color="#0000ff" size="2">比较简单的那种，句子都在内存中。还有一种就是文章在文件中，然后数不同单词的数目，最近比较流行，不过实现起来比较复杂，就说一下思路吧。建一个27叉树(或者兄弟孩子树)，然后从文件里读单词，在树上一个字母一个字母数，单词结束做个标记。如果某个单词数过了就不用计数。</font>
		<br />
		<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">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> CountWord(</span>
				<span style="COLOR: #0000ff">const</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">char</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">text, </span>
				<span style="COLOR: #0000ff">char</span>
				<span style="COLOR: #000000"> seperator)<br /><img id="Codehighlighter1_48_274_Open_Image" onclick="this.style.display='none'; Codehighlighter1_48_274_Open_Text.style.display='none'; Codehighlighter1_48_274_Closed_Image.style.display='inline'; Codehighlighter1_48_274_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_48_274_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_48_274_Closed_Text.style.display='none'; Codehighlighter1_48_274_Open_Image.style.display='inline'; Codehighlighter1_48_274_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_48_274_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_48_274_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> count </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">bool</span>
						<span style="COLOR: #000000"> emergence </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">false</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">while</span>
						<span style="COLOR: #000000"> (</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000">text)<br /><img id="Codehighlighter1_108_249_Open_Image" onclick="this.style.display='none'; Codehighlighter1_108_249_Open_Text.style.display='none'; Codehighlighter1_108_249_Closed_Image.style.display='inline'; Codehighlighter1_108_249_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_108_249_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_108_249_Closed_Text.style.display='none'; Codehighlighter1_108_249_Open_Image.style.display='inline'; Codehighlighter1_108_249_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_108_249_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_108_249_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000"> (</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">text</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">!=</span>
								<span style="COLOR: #000000"> seperator)<br /><img id="Codehighlighter1_140_208_Open_Image" onclick="this.style.display='none'; Codehighlighter1_140_208_Open_Text.style.display='none'; Codehighlighter1_140_208_Closed_Image.style.display='inline'; Codehighlighter1_140_208_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_140_208_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_140_208_Closed_Text.style.display='none'; Codehighlighter1_140_208_Open_Image.style.display='inline'; Codehighlighter1_140_208_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_140_208_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_140_208_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000"> (</span>
										<span style="COLOR: #000000">!</span>
										<span style="COLOR: #000000">emergence)<br /><img id="Codehighlighter1_164_204_Open_Image" onclick="this.style.display='none'; Codehighlighter1_164_204_Open_Text.style.display='none'; Codehighlighter1_164_204_Closed_Image.style.display='inline'; Codehighlighter1_164_204_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_164_204_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_164_204_Closed_Text.style.display='none'; Codehighlighter1_164_204_Open_Image.style.display='inline'; Codehighlighter1_164_204_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
										<span id="Codehighlighter1_164_204_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_164_204_Open_Text">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                emergence </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #0000ff">true</span>
												<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                count</span>
												<span style="COLOR: #000000">++</span>
												<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">else</span>
								<span style="COLOR: #000000">
										<br />
										<img id="Codehighlighter1_219_245_Open_Image" onclick="this.style.display='none'; Codehighlighter1_219_245_Open_Text.style.display='none'; Codehighlighter1_219_245_Closed_Image.style.display='inline'; Codehighlighter1_219_245_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
										<img id="Codehighlighter1_219_245_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_219_245_Closed_Text.style.display='none'; Codehighlighter1_219_245_Open_Image.style.display='inline'; Codehighlighter1_219_245_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_219_245_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_219_245_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            emergence </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">false</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">while</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> count;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
		<font face="Verdana" color="#0000ff" size="2">记录切开的单词版本<br /><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"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">vector</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> std::vector;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> CountWord2(</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">text, </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000"> seperator, vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">*&gt;&amp;</span><span style="COLOR: #000000"> words)<br /><img id="Codehighlighter1_108_678_Open_Image" onclick="this.style.display='none'; Codehighlighter1_108_678_Open_Text.style.display='none'; Codehighlighter1_108_678_Closed_Image.style.display='inline'; Codehighlighter1_108_678_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_108_678_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_108_678_Closed_Text.style.display='none'; Codehighlighter1_108_678_Open_Image.style.display='inline'; Codehighlighter1_108_678_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_108_678_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_108_678_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> count </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> iTokenScanner </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> iWritePos </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> iWordStart;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> (text[iTokenScanner])<br /><img id="Codehighlighter1_218_653_Open_Image" onclick="this.style.display='none'; Codehighlighter1_218_653_Open_Text.style.display='none'; Codehighlighter1_218_653_Closed_Image.style.display='inline'; Codehighlighter1_218_653_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_218_653_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_218_653_Closed_Text.style.display='none'; Codehighlighter1_218_653_Open_Image.style.display='inline'; Codehighlighter1_218_653_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_218_653_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_218_653_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (text[iTokenScanner] </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> seperator)<br /><img id="Codehighlighter1_262_614_Open_Image" onclick="this.style.display='none'; Codehighlighter1_262_614_Open_Text.style.display='none'; Codehighlighter1_262_614_Closed_Image.style.display='inline'; Codehighlighter1_262_614_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_262_614_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_262_614_Closed_Text.style.display='none'; Codehighlighter1_262_614_Open_Image.style.display='inline'; Codehighlighter1_262_614_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span id="Codehighlighter1_262_614_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_262_614_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            iWordStart </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> iTokenScanner;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> (text[iTokenScanner] </span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000"> text[iTokenScanner] </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> seperator)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                iTokenScanner</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            words.push_back(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">[iTokenScanner </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000"> iWordStart </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> (iWordStart </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> iTokenScanner)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                words[count][iWritePos</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> text[iWordStart</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            words[count][iWritePos] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">\0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            iWritePos </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            count</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br /><img id="Codehighlighter1_625_649_Open_Image" onclick="this.style.display='none'; Codehighlighter1_625_649_Open_Text.style.display='none'; Codehighlighter1_625_649_Closed_Image.style.display='inline'; Codehighlighter1_625_649_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_625_649_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_625_649_Closed_Text.style.display='none'; Codehighlighter1_625_649_Open_Image.style.display='inline'; Codehighlighter1_625_649_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span id="Codehighlighter1_625_649_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_625_649_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            iTokenScanner</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">while</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> count;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div></font>
<img src ="http://www.cppblog.com/Winux32/aggbug/15501.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Winux32/" target="_blank">Charles</a> 2006-11-21 11:06 <a href="http://www.cppblog.com/Winux32/archive/2006/11/21/15501.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>抹掉多余空格</title><link>http://www.cppblog.com/Winux32/archive/2006/11/17/15308.html</link><dc:creator>Charles</dc:creator><author>Charles</author><pubDate>Fri, 17 Nov 2006 09:55:00 GMT</pubDate><guid>http://www.cppblog.com/Winux32/archive/2006/11/17/15308.html</guid><wfw:comment>http://www.cppblog.com/Winux32/comments/15308.html</wfw:comment><comments>http://www.cppblog.com/Winux32/archive/2006/11/17/15308.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Winux32/comments/commentRss/15308.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Winux32/services/trackbacks/15308.html</trackback:ping><description><![CDATA[
		<font face="Verdana" color="#0000ff" size="2">MS ATC 出过这样一道题。"I'd    like   to    join MS,      BUT    they    reject" -&gt; "I'd like to join MS, BUT they reject"<br /><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"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> RemoveSpace(</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">text)<br /><img id="Codehighlighter1_29_366_Open_Image" onclick="this.style.display='none'; Codehighlighter1_29_366_Open_Text.style.display='none'; Codehighlighter1_29_366_Closed_Image.style.display='inline'; Codehighlighter1_29_366_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_29_366_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_29_366_Closed_Text.style.display='none'; Codehighlighter1_29_366_Open_Image.style.display='inline'; Codehighlighter1_29_366_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_29_366_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_29_366_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> src </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">, dst </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000"> candidate </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">\x20</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000"> bFirst </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">do</span><span style="COLOR: #000000"><br /><img id="Codehighlighter1_109_343_Open_Image" onclick="this.style.display='none'; Codehighlighter1_109_343_Open_Text.style.display='none'; Codehighlighter1_109_343_Closed_Image.style.display='inline'; Codehighlighter1_109_343_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_109_343_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_109_343_Closed_Text.style.display='none'; Codehighlighter1_109_343_Open_Image.style.display='inline'; Codehighlighter1_109_343_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_109_343_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_109_343_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (text[src] </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> candidate)<br /><img id="Codehighlighter1_143_211_Open_Image" onclick="this.style.display='none'; Codehighlighter1_143_211_Open_Text.style.display='none'; Codehighlighter1_143_211_Closed_Image.style.display='inline'; Codehighlighter1_143_211_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_143_211_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_143_211_Closed_Text.style.display='none'; Codehighlighter1_143_211_Open_Image.style.display='inline'; Codehighlighter1_143_211_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span id="Codehighlighter1_143_211_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_143_211_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            text[dst</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> text[src];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">bFirst)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                bFirst </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br /><img id="Codehighlighter1_222_339_Open_Image" onclick="this.style.display='none'; Codehighlighter1_222_339_Open_Text.style.display='none'; Codehighlighter1_222_339_Closed_Image.style.display='inline'; Codehighlighter1_222_339_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_222_339_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_222_339_Closed_Text.style.display='none'; Codehighlighter1_222_339_Open_Image.style.display='inline'; Codehighlighter1_222_339_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span id="Codehighlighter1_222_339_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_222_339_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">treat first space as normal char</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #000000">            </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (bFirst)<br /><img id="Codehighlighter1_280_334_Open_Image" onclick="this.style.display='none'; Codehighlighter1_280_334_Open_Text.style.display='none'; Codehighlighter1_280_334_Closed_Image.style.display='inline'; Codehighlighter1_280_334_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_280_334_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_280_334_Closed_Text.style.display='none'; Codehighlighter1_280_334_Open_Image.style.display='inline'; Codehighlighter1_280_334_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span><span id="Codehighlighter1_280_334_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_280_334_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                text[dst</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> text[src];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                bFirst </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span></span><span style="COLOR: #000000">    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> (text[src</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">]);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div><br /></font>
<img src ="http://www.cppblog.com/Winux32/aggbug/15308.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Winux32/" target="_blank">Charles</a> 2006-11-17 17:55 <a href="http://www.cppblog.com/Winux32/archive/2006/11/17/15308.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>移除字符</title><link>http://www.cppblog.com/Winux32/archive/2006/11/17/15307.html</link><dc:creator>Charles</dc:creator><author>Charles</author><pubDate>Fri, 17 Nov 2006 09:52:00 GMT</pubDate><guid>http://www.cppblog.com/Winux32/archive/2006/11/17/15307.html</guid><wfw:comment>http://www.cppblog.com/Winux32/comments/15307.html</wfw:comment><comments>http://www.cppblog.com/Winux32/archive/2006/11/17/15307.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Winux32/comments/commentRss/15307.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Winux32/services/trackbacks/15307.html</trackback:ping><description><![CDATA[
		<font face="Verdana" color="#0000ff" size="2">将给定字符从字符串中移除<br />如，text = "Could you write it down?", candidates = "ouit" -&gt; text = "Cld y wre  dwn"<br /><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"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> RemoveChars(</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">text, </span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">candidates)<br /><img id="Codehighlighter1_53_460_Open_Image" onclick="this.style.display='none'; Codehighlighter1_53_460_Open_Text.style.display='none'; Codehighlighter1_53_460_Closed_Image.style.display='inline'; Codehighlighter1_53_460_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_53_460_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_53_460_Closed_Text.style.display='none'; Codehighlighter1_53_460_Open_Image.style.display='inline'; Codehighlighter1_53_460_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_53_460_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_53_460_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> src, dst;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">arrToBeRemoved </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">256</span><span style="COLOR: #000000">]();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">explicit initialize, though new()</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (src </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; src </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000"> arrToBeRemoved </span><span style="COLOR: #000000">/</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">); src</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        arrToBeRemoved[src] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (src </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; candidates[src] </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">\0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">; src</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        arrToBeRemoved[candidates[src]] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    src </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> dst </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">do</span><span style="COLOR: #000000"> <br /><img id="Codehighlighter1_363_437_Open_Image" onclick="this.style.display='none'; Codehighlighter1_363_437_Open_Text.style.display='none'; Codehighlighter1_363_437_Closed_Image.style.display='inline'; Codehighlighter1_363_437_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_363_437_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_363_437_Closed_Text.style.display='none'; Codehighlighter1_363_437_Open_Image.style.display='inline'; Codehighlighter1_363_437_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_363_437_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_363_437_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">arrToBeRemoved[text[src]])<br /><img id="Codehighlighter1_401_433_Open_Image" onclick="this.style.display='none'; Codehighlighter1_401_433_Open_Text.style.display='none'; Codehighlighter1_401_433_Closed_Image.style.display='inline'; Codehighlighter1_401_433_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_401_433_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_401_433_Closed_Text.style.display='none'; Codehighlighter1_401_433_Open_Image.style.display='inline'; Codehighlighter1_401_433_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span id="Codehighlighter1_401_433_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_401_433_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            text[dst</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> text[src];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(text[src</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">]);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div></font>
<img src ="http://www.cppblog.com/Winux32/aggbug/15307.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Winux32/" target="_blank">Charles</a> 2006-11-17 17:52 <a href="http://www.cppblog.com/Winux32/archive/2006/11/17/15307.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>整数与字符串互相转换</title><link>http://www.cppblog.com/Winux32/archive/2006/11/17/15291.html</link><dc:creator>Charles</dc:creator><author>Charles</author><pubDate>Fri, 17 Nov 2006 05:01:00 GMT</pubDate><guid>http://www.cppblog.com/Winux32/archive/2006/11/17/15291.html</guid><wfw:comment>http://www.cppblog.com/Winux32/comments/15291.html</wfw:comment><comments>http://www.cppblog.com/Winux32/archive/2006/11/17/15291.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Winux32/comments/commentRss/15291.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Winux32/services/trackbacks/15291.html</trackback:ping><description><![CDATA[
		<font color="#0000ff">
				<font face="Verdana" size="2">加了对负数和溢出的处理，其他出错考虑较少，凑合看</font>
				<br />  
<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"><font size="2"><font face="Verdana"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">climits</span><span style="COLOR: #000000">&gt;</span></font></font><span style="COLOR: #000000"><br /><font face="Verdana" size="2"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></font></span><font size="2"><font face="Verdana"><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000"> Str2Int(</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">s, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span></font></font><font size="2"><font face="Verdana"><span style="COLOR: #000000">result)<br /><img id="Codehighlighter1_60_462_Open_Image" onclick="this.style.display='none'; Codehighlighter1_60_462_Open_Text.style.display='none'; Codehighlighter1_60_462_Closed_Image.style.display='inline'; Codehighlighter1_60_462_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_60_462_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_60_462_Closed_Text.style.display='none'; Codehighlighter1_60_462_Open_Image.style.display='inline'; Codehighlighter1_60_462_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_60_462_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span></font></font><span id="Codehighlighter1_60_462_Open_Text"><font size="2"><font face="Verdana"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span></font></font><font size="2"><font face="Verdana"><span style="COLOR: #000000"> digit;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">result </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span></font></font><font size="2"><font face="Verdana"><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000"> isNeg </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">false</span></font></font><font size="2"><font face="Verdana"><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span></font></font><font size="2"><font face="Verdana"><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (s[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">] </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">'</span></font></font><font size="2"><font face="Verdana"><span style="COLOR: #000000">)<br /><img id="Codehighlighter1_141_169_Open_Image" onclick="this.style.display='none'; Codehighlighter1_141_169_Open_Text.style.display='none'; Codehighlighter1_141_169_Closed_Image.style.display='inline'; Codehighlighter1_141_169_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_141_169_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_141_169_Closed_Text.style.display='none'; Codehighlighter1_141_169_Open_Image.style.display='inline'; Codehighlighter1_141_169_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_141_169_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span></font></font><span id="Codehighlighter1_141_169_Open_Text"><font size="2"><font face="Verdana"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        isNeg </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">true</span></font></font><font size="2"><font face="Verdana"><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span></font></font><span style="COLOR: #000000"><font face="Verdana" size="2">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</font></span></span><span style="COLOR: #000000"><br /><font face="Verdana" size="2"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </font></span><font size="2"><font face="Verdana"><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> (s[i] </span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000"> s[i] </span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">'</span></font></font><font size="2"><font face="Verdana"><span style="COLOR: #000000">)<br /><img id="Codehighlighter1_210_350_Open_Image" onclick="this.style.display='none'; Codehighlighter1_210_350_Open_Text.style.display='none'; Codehighlighter1_210_350_Closed_Image.style.display='inline'; Codehighlighter1_210_350_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_210_350_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_210_350_Closed_Text.style.display='none'; Codehighlighter1_210_350_Open_Image.style.display='inline'; Codehighlighter1_210_350_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_210_350_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span></font></font><span id="Codehighlighter1_210_350_Open_Text"><font size="2"><font face="Verdana"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">result </span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000"> (INT_MAX </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000"> (digit </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> s[i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">] </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)) </span><span style="COLOR: #000000">/</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">10</span></font></font><font size="2"><font face="Verdana"><span style="COLOR: #000000">)<br /><img id="Codehighlighter1_272_314_Open_Image" onclick="this.style.display='none'; Codehighlighter1_272_314_Open_Text.style.display='none'; Codehighlighter1_272_314_Closed_Image.style.display='inline'; Codehighlighter1_272_314_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_272_314_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_272_314_Closed_Text.style.display='none'; Codehighlighter1_272_314_Open_Image.style.display='inline'; Codehighlighter1_272_314_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span id="Codehighlighter1_272_314_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span></font></font><span id="Codehighlighter1_272_314_Open_Text"><font size="2"><font face="Verdana"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">result </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">10</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">result) </span><span style="COLOR: #000000">+</span></font></font><span style="COLOR: #000000"><font face="Verdana" size="2"> digit;    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</font></span></span><font size="2"><font face="Verdana"><span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">else</span></font></font><span style="COLOR: #000000"><br /><font face="Verdana" size="2"><img id="Codehighlighter1_326_347_Open_Image" onclick="this.style.display='none'; Codehighlighter1_326_347_Open_Text.style.display='none'; Codehighlighter1_326_347_Closed_Image.style.display='inline'; Codehighlighter1_326_347_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_326_347_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_326_347_Closed_Text.style.display='none'; Codehighlighter1_326_347_Open_Image.style.display='inline'; Codehighlighter1_326_347_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </font></span><span id="Codehighlighter1_326_347_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><font face="Verdana" size="2"><img src="http://www.cppblog.com/images/dot.gif" /></font></span><span id="Codehighlighter1_326_347_Open_Text"><font size="2"><font face="Verdana"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">false</span></font></font><span style="COLOR: #000000"><font face="Verdana" size="2">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</font></span></span><span style="COLOR: #000000"><br /><font face="Verdana" size="2"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</font></span></span><font size="2"><font face="Verdana"><span style="COLOR: #008000">//</span><span style="COLOR: #008000">while</span></font></font><span style="COLOR: #008000"><br /><font face="Verdana" size="2"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></font></span><font size="2"><font face="Verdana"><span style="COLOR: #000000">    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">s[i] </span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000"> s[</span><span style="COLOR: #000000">0</span></font></font><font size="2"><font face="Verdana"><span style="COLOR: #000000">])<br /><img id="Codehighlighter1_382_432_Open_Image" onclick="this.style.display='none'; Codehighlighter1_382_432_Open_Text.style.display='none'; Codehighlighter1_382_432_Closed_Image.style.display='inline'; Codehighlighter1_382_432_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_382_432_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_382_432_Closed_Text.style.display='none'; Codehighlighter1_382_432_Open_Image.style.display='inline'; Codehighlighter1_382_432_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_382_432_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span></font></font><span id="Codehighlighter1_382_432_Open_Text"><font size="2"><font face="Verdana"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">if</span></font></font><font size="2"><font face="Verdana"><span style="COLOR: #000000"> (isNeg)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">result </span><span style="COLOR: #000000">*=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span></font></font><font size="2"><font face="Verdana"><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">true</span></font></font><span style="COLOR: #000000"><font face="Verdana" size="2">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</font></span></span><span style="COLOR: #000000"><br /><font face="Verdana" size="2"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </font></span><span style="COLOR: #0000ff"><font face="Verdana" size="2">else</font></span><span style="COLOR: #000000"><br /><font face="Verdana" size="2"><img id="Codehighlighter1_441_460_Open_Image" onclick="this.style.display='none'; Codehighlighter1_441_460_Open_Text.style.display='none'; Codehighlighter1_441_460_Closed_Image.style.display='inline'; Codehighlighter1_441_460_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_441_460_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_441_460_Closed_Text.style.display='none'; Codehighlighter1_441_460_Open_Image.style.display='inline'; Codehighlighter1_441_460_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </font></span><span id="Codehighlighter1_441_460_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><font face="Verdana" size="2"><img src="http://www.cppblog.com/images/dot.gif" /></font></span><span id="Codehighlighter1_441_460_Open_Text"><font size="2"><font face="Verdana"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">false</span></font></font><span style="COLOR: #000000"><font face="Verdana" size="2">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</font></span></span><span style="COLOR: #000000"><br /><font face="Verdana" size="2"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</font></span></span></div><font face="Verdana" size="2"><br />混杂合法字串</font><br /><br /><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"><font size="2"><font face="Verdana"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">climits</span><span style="COLOR: #000000">&gt;</span></font></font><span style="COLOR: #000000"><br /><font face="Verdana" size="2"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></font></span><font size="2"><font face="Verdana"><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000"> MixedStr2Int(</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">s, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span></font></font><font size="2"><font face="Verdana"><span style="COLOR: #000000">result)<br /><img id="Codehighlighter1_65_345_Open_Image" onclick="this.style.display='none'; Codehighlighter1_65_345_Open_Text.style.display='none'; Codehighlighter1_65_345_Closed_Image.style.display='inline'; Codehighlighter1_65_345_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_65_345_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_65_345_Closed_Text.style.display='none'; Codehighlighter1_65_345_Open_Image.style.display='inline'; Codehighlighter1_65_345_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_65_345_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span></font></font><span id="Codehighlighter1_65_345_Open_Text"><font size="2"><font face="Verdana"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span></font></font><font size="2"><font face="Verdana"><span style="COLOR: #000000"> digit;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">result </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span></font></font><font size="2"><font face="Verdana"><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; s[i] </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">\0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">; i</span><span style="COLOR: #000000">++</span></font></font><font size="2"><font face="Verdana"><span style="COLOR: #000000">)<br /><img id="Codehighlighter1_133_323_Open_Image" onclick="this.style.display='none'; Codehighlighter1_133_323_Open_Text.style.display='none'; Codehighlighter1_133_323_Closed_Image.style.display='inline'; Codehighlighter1_133_323_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_133_323_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_133_323_Closed_Text.style.display='none'; Codehighlighter1_133_323_Open_Image.style.display='inline'; Codehighlighter1_133_323_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_133_323_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span></font></font><span id="Codehighlighter1_133_323_Open_Text"><font size="2"><font face="Verdana"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (s[i] </span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000"> s[i] </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">'</span></font></font><font size="2"><font face="Verdana"><span style="COLOR: #000000">)<br /><img id="Codehighlighter1_169_316_Open_Image" onclick="this.style.display='none'; Codehighlighter1_169_316_Open_Text.style.display='none'; Codehighlighter1_169_316_Closed_Image.style.display='inline'; Codehighlighter1_169_316_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_169_316_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_169_316_Closed_Text.style.display='none'; Codehighlighter1_169_316_Open_Image.style.display='inline'; Codehighlighter1_169_316_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span id="Codehighlighter1_169_316_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span></font></font><span id="Codehighlighter1_169_316_Open_Text"><font size="2"><font face="Verdana"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">result </span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000"> (INT_MAX </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000"> (digit </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> s[i] </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)) </span><span style="COLOR: #000000">/</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">10</span></font></font><font size="2"><font face="Verdana"><span style="COLOR: #000000">)<br /><img id="Codehighlighter1_231_275_Open_Image" onclick="this.style.display='none'; Codehighlighter1_231_275_Open_Text.style.display='none'; Codehighlighter1_231_275_Closed_Image.style.display='inline'; Codehighlighter1_231_275_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_231_275_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_231_275_Closed_Text.style.display='none'; Codehighlighter1_231_275_Open_Image.style.display='inline'; Codehighlighter1_231_275_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span><span id="Codehighlighter1_231_275_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span></font></font><span id="Codehighlighter1_231_275_Open_Text"><font size="2"><font face="Verdana"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">result </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">10</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">result) </span><span style="COLOR: #000000">+</span></font></font><span style="COLOR: #000000"><font face="Verdana" size="2"> digit;    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</font></span></span><font size="2"><font face="Verdana"><span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="COLOR: #0000ff">else</span></font></font><span style="COLOR: #000000"><br /><font face="Verdana" size="2"><img id="Codehighlighter1_289_312_Open_Image" onclick="this.style.display='none'; Codehighlighter1_289_312_Open_Text.style.display='none'; Codehighlighter1_289_312_Closed_Image.style.display='inline'; Codehighlighter1_289_312_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_289_312_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_289_312_Closed_Text.style.display='none'; Codehighlighter1_289_312_Open_Image.style.display='inline'; Codehighlighter1_289_312_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </font></span><span id="Codehighlighter1_289_312_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><font face="Verdana" size="2"><img src="http://www.cppblog.com/images/dot.gif" /></font></span><span id="Codehighlighter1_289_312_Open_Text"><font size="2"><font face="Verdana"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">false</span></font></font><span style="COLOR: #000000"><font face="Verdana" size="2">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</font></span></span><span style="COLOR: #000000"><br /><font face="Verdana" size="2"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</font></span></span><span style="COLOR: #000000"><font face="Verdana" size="2"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</font></span></span><font size="2"><font face="Verdana"><span style="COLOR: #008000">//</span><span style="COLOR: #008000">for</span></font></font><span style="COLOR: #008000"><br /><font face="Verdana" size="2"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></font></span><span style="COLOR: #000000"><br /><font face="Verdana" size="2"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </font></span><font size="2"><font face="Verdana"><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">true</span></font></font><span style="COLOR: #000000"><font face="Verdana" size="2">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</font></span></span></div><br /></font>
		<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">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">bool</span>
				<span style="COLOR: #000000"> Int2Str(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> n, </span>
				<span style="COLOR: #0000ff">char</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">arr, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> len)<br /><img id="Codehighlighter1_40_520_Open_Image" onclick="this.style.display='none'; Codehighlighter1_40_520_Open_Text.style.display='none'; Codehighlighter1_40_520_Closed_Image.style.display='inline'; Codehighlighter1_40_520_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_40_520_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_40_520_Closed_Text.style.display='none'; Codehighlighter1_40_520_Open_Image.style.display='inline'; Codehighlighter1_40_520_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_40_520_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_40_520_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> start </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">, end </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">bool</span>
						<span style="COLOR: #000000"> isNeg </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">false</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (n </span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_101_131_Open_Image" onclick="this.style.display='none'; Codehighlighter1_101_131_Open_Text.style.display='none'; Codehighlighter1_101_131_Closed_Image.style.display='inline'; Codehighlighter1_101_131_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_101_131_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_101_131_Closed_Text.style.display='none'; Codehighlighter1_101_131_Open_Image.style.display='inline'; Codehighlighter1_101_131_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_101_131_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_101_131_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        n </span>
								<span style="COLOR: #000000">*=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        isNeg </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">true</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">do</span>
						<span style="COLOR: #000000"> <br /><img id="Codehighlighter1_140_195_Open_Image" onclick="this.style.display='none'; Codehighlighter1_140_195_Open_Text.style.display='none'; Codehighlighter1_140_195_Closed_Image.style.display='inline'; Codehighlighter1_140_195_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_140_195_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_140_195_Closed_Text.style.display='none'; Codehighlighter1_140_195_Open_Image.style.display='inline'; Codehighlighter1_140_195_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_140_195_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_140_195_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        arr[end</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">] </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> n </span>
								<span style="COLOR: #000000">%</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">10</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">'</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">'</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        n </span>
								<span style="COLOR: #000000">/=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">10</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        len</span>
								<span style="COLOR: #000000">--</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">while</span>
						<span style="COLOR: #000000">(n </span>
						<span style="COLOR: #000000">&amp;&amp;</span>
						<span style="COLOR: #000000"> (len </span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (len </span>
						<span style="COLOR: #000000">&lt;=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_237_256_Open_Image" onclick="this.style.display='none'; Codehighlighter1_237_256_Open_Text.style.display='none'; Codehighlighter1_237_256_Closed_Image.style.display='inline'; Codehighlighter1_237_256_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_237_256_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_237_256_Closed_Text.style.display='none'; Codehighlighter1_237_256_Open_Image.style.display='inline'; Codehighlighter1_237_256_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_237_256_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_237_256_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">false</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (isNeg)<br /><img id="Codehighlighter1_272_354_Open_Image" onclick="this.style.display='none'; Codehighlighter1_272_354_Open_Text.style.display='none'; Codehighlighter1_272_354_Closed_Image.style.display='inline'; Codehighlighter1_272_354_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_272_354_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_272_354_Closed_Text.style.display='none'; Codehighlighter1_272_354_Open_Image.style.display='inline'; Codehighlighter1_272_354_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_272_354_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_272_354_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000"> (len </span>
								<span style="COLOR: #000000">&gt;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_291_326_Open_Image" onclick="this.style.display='none'; Codehighlighter1_291_326_Open_Text.style.display='none'; Codehighlighter1_291_326_Closed_Image.style.display='inline'; Codehighlighter1_291_326_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_291_326_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_291_326_Closed_Text.style.display='none'; Codehighlighter1_291_326_Open_Image.style.display='inline'; Codehighlighter1_291_326_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_291_326_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_291_326_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            arr[end</span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000">] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">'</span>
										<span style="COLOR: #000000">-</span>
										<span style="COLOR: #000000">'</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            len</span>
										<span style="COLOR: #000000">--</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">else</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />             </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">false</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    arr[end</span>
						<span style="COLOR: #000000">--</span>
						<span style="COLOR: #000000">] </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">'</span>
						<span style="COLOR: #000000">\0</span>
						<span style="COLOR: #000000">'</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">while</span>
						<span style="COLOR: #000000"> (start </span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000"> end)<br /><img id="Codehighlighter1_401_503_Open_Image" onclick="this.style.display='none'; Codehighlighter1_401_503_Open_Text.style.display='none'; Codehighlighter1_401_503_Closed_Image.style.display='inline'; Codehighlighter1_401_503_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_401_503_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_401_503_Closed_Text.style.display='none'; Codehighlighter1_401_503_Open_Image.style.display='inline'; Codehighlighter1_401_503_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_401_503_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_401_503_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        arr[start] </span>
								<span style="COLOR: #000000">^=</span>
								<span style="COLOR: #000000"> arr[end];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        arr[end] </span>
								<span style="COLOR: #000000">^=</span>
								<span style="COLOR: #000000"> arr[start];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        arr[start] </span>
								<span style="COLOR: #000000">^=</span>
								<span style="COLOR: #000000"> arr[end];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        start</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        end</span>
								<span style="COLOR: #000000">--</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">true</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
<img src ="http://www.cppblog.com/Winux32/aggbug/15291.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Winux32/" target="_blank">Charles</a> 2006-11-17 13:01 <a href="http://www.cppblog.com/Winux32/archive/2006/11/17/15291.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>根据给定token翻转字符串</title><link>http://www.cppblog.com/Winux32/archive/2006/11/17/15289.html</link><dc:creator>Charles</dc:creator><author>Charles</author><pubDate>Fri, 17 Nov 2006 03:28:00 GMT</pubDate><guid>http://www.cppblog.com/Winux32/archive/2006/11/17/15289.html</guid><wfw:comment>http://www.cppblog.com/Winux32/comments/15289.html</wfw:comment><comments>http://www.cppblog.com/Winux32/archive/2006/11/17/15289.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Winux32/comments/commentRss/15289.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Winux32/services/trackbacks/15289.html</trackback:ping><description><![CDATA[
		<p>
				<font face="Verdana" color="#0000ff" size="2">"ab<font color="#ff0000">cd</font>efg" token = "cd" -&gt; "gfe<font color="#ff0000">cd</font><font color="#0000ff">ba</font>"<br /></font>
		</p>
		<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">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">cstring</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">bool</span>
				<span style="COLOR: #000000"> MirrorByToken(</span>
				<span style="COLOR: #0000ff">char</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">text, </span>
				<span style="COLOR: #0000ff">const</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">char</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">token)<br /><img id="Codehighlighter1_69_321_Open_Image" onclick="this.style.display='none'; Codehighlighter1_69_321_Open_Text.style.display='none'; Codehighlighter1_69_321_Closed_Image.style.display='inline'; Codehighlighter1_69_321_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_69_321_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_69_321_Closed_Text.style.display='none'; Codehighlighter1_69_321_Open_Image.style.display='inline'; Codehighlighter1_69_321_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_69_321_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_69_321_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> nTextLen </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> strlen(text);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> nTokenLen </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> strlen(token);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> iTokenPos </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> BM(text, token);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (iTokenPos </span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">false</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    ReverseString(text, iTokenPos, iTokenPos </span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000"> nTokenLen </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    ReverseString(text, </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">, nTextLen </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">true</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
		<font face="Verdana" color="#0000ff" size="2">这里引用了两个函数<br /></font>
		<a class="" title="" href="/Winux32/archive/2006/11/16/15251.html" target="_blank">
				<font face="Verdana" color="#0000ff" size="2">BM</font>
		</a>
		<br />
		<a class="" title="" href="/Winux32/archive/2006/11/16/15253.html" target="_blank">
				<font face="Verdana" color="#0000ff" size="2">ReverseString</font>
		</a>
		<br />
		<font face="Verdana" color="#0000ff" size="2">原理很简单，先找到token并翻转，再翻转整个串<br /></font>
<img src ="http://www.cppblog.com/Winux32/aggbug/15289.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Winux32/" target="_blank">Charles</a> 2006-11-17 11:28 <a href="http://www.cppblog.com/Winux32/archive/2006/11/17/15289.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>按单词翻转句子</title><link>http://www.cppblog.com/Winux32/archive/2006/11/16/15253.html</link><dc:creator>Charles</dc:creator><author>Charles</author><pubDate>Thu, 16 Nov 2006 10:50:00 GMT</pubDate><guid>http://www.cppblog.com/Winux32/archive/2006/11/16/15253.html</guid><wfw:comment>http://www.cppblog.com/Winux32/comments/15253.html</wfw:comment><comments>http://www.cppblog.com/Winux32/archive/2006/11/16/15253.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Winux32/comments/commentRss/15253.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Winux32/services/trackbacks/15253.html</trackback:ping><description><![CDATA[
		<p>
				<font face="Verdana" color="#0000ff" size="2">MS面试曾出过这样一道题目，将给定字符串按单词翻转，如，"This is Charles" -&gt; "Charles is This"<br /><br />方法一，需要额外缓冲区<br /></font>
		</p>
		<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"> 1</span>
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">cstring</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #008080"> 2</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> ReverseByWords(</span>
				<span style="COLOR: #0000ff">char</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">s, </span>
				<span style="COLOR: #0000ff">char</span>
				<span style="COLOR: #000000"> seperator)<br /></span>
				<span style="COLOR: #008080"> 3</span>
				<span style="COLOR: #000000">
						<img id="Codehighlighter1_64_713_Open_Image" onclick="this.style.display='none'; Codehighlighter1_64_713_Open_Text.style.display='none'; Codehighlighter1_64_713_Closed_Image.style.display='inline'; Codehighlighter1_64_713_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_64_713_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_64_713_Closed_Text.style.display='none'; Codehighlighter1_64_713_Open_Image.style.display='inline'; Codehighlighter1_64_713_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				</span>
				<span id="Codehighlighter1_64_713_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_64_713_Open_Text">
						<span style="COLOR: #000000">{<br /></span>
						<span style="COLOR: #008080"> 4</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> iRevTokenScanner </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> strlen(s) </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">;<br /></span>
						<span style="COLOR: #008080"> 5</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">char</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000">buffer </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">new</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">char</span>
						<span style="COLOR: #000000">[iRevTokenScanner </span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">2</span>
						<span style="COLOR: #000000">]();<br /></span>
						<span style="COLOR: #008080"> 6</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> iWritePos </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /></span>
						<span style="COLOR: #008080"> 7</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> iWordEnd, iWordReadPos;<br /></span>
						<span style="COLOR: #008080"> 8</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
						</span>
						<span style="COLOR: #008080"> 9</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">while</span>
						<span style="COLOR: #000000"> (iRevTokenScanner </span>
						<span style="COLOR: #000000">&gt;=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">)<br /></span>
						<span style="COLOR: #008080">10</span>
						<span style="COLOR: #000000">
								<img id="Codehighlighter1_237_608_Open_Image" onclick="this.style.display='none'; Codehighlighter1_237_608_Open_Text.style.display='none'; Codehighlighter1_237_608_Closed_Image.style.display='inline'; Codehighlighter1_237_608_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_237_608_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_237_608_Closed_Text.style.display='none'; Codehighlighter1_237_608_Open_Image.style.display='inline'; Codehighlighter1_237_608_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_237_608_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_237_608_Open_Text">
								<span style="COLOR: #000000">{<br /></span>
								<span style="COLOR: #008080">11</span>
								<span style="COLOR: #000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000"> (s[iRevTokenScanner] </span>
								<span style="COLOR: #000000">!=</span>
								<span style="COLOR: #000000"> seperator)<br /></span>
								<span style="COLOR: #008080">12</span>
								<span style="COLOR: #000000">
										<img id="Codehighlighter1_281_541_Open_Image" onclick="this.style.display='none'; Codehighlighter1_281_541_Open_Text.style.display='none'; Codehighlighter1_281_541_Closed_Image.style.display='inline'; Codehighlighter1_281_541_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
										<img id="Codehighlighter1_281_541_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_281_541_Closed_Text.style.display='none'; Codehighlighter1_281_541_Open_Image.style.display='inline'; Codehighlighter1_281_541_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_281_541_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_281_541_Open_Text">
										<span style="COLOR: #000000">{<br /></span>
										<span style="COLOR: #008080">13</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            iWordEnd </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> iRevTokenScanner;<br /></span>
										<span style="COLOR: #008080">14</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            <br /></span>
										<span style="COLOR: #008080">15</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">while</span>
										<span style="COLOR: #000000"> (iRevTokenScanner </span>
										<span style="COLOR: #000000">&gt;=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">&amp;&amp;</span>
										<span style="COLOR: #000000">  s[iRevTokenScanner] </span>
										<span style="COLOR: #000000">!=</span>
										<span style="COLOR: #000000"> seperator)<br /></span>
										<span style="COLOR: #008080">16</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                iRevTokenScanner</span>
										<span style="COLOR: #000000">--</span>
										<span style="COLOR: #000000">;<br /></span>
										<span style="COLOR: #008080">17</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            <br /></span>
										<span style="COLOR: #008080">18</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            iWordReadPos </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> iRevTokenScanner </span>
										<span style="COLOR: #000000">+</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">;<br /></span>
										<span style="COLOR: #008080">19</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
												<br />
										</span>
										<span style="COLOR: #008080">20</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">while</span>
										<span style="COLOR: #000000"> (iWordReadPos </span>
										<span style="COLOR: #000000">&lt;=</span>
										<span style="COLOR: #000000"> iWordEnd)<br /></span>
										<span style="COLOR: #008080">21</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                buffer[iWritePos</span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000">] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> s[iWordReadPos</span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000">];<br /></span>
										<span style="COLOR: #008080">22</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
								</span>
								<span style="COLOR: #008080">23</span>
								<span style="COLOR: #000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">else</span>
								<span style="COLOR: #000000">
										<br />
								</span>
								<span style="COLOR: #008080">24</span>
								<span style="COLOR: #000000">
										<img id="Codehighlighter1_552_604_Open_Image" onclick="this.style.display='none'; Codehighlighter1_552_604_Open_Text.style.display='none'; Codehighlighter1_552_604_Closed_Image.style.display='inline'; Codehighlighter1_552_604_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
										<img id="Codehighlighter1_552_604_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_552_604_Closed_Text.style.display='none'; Codehighlighter1_552_604_Open_Image.style.display='inline'; Codehighlighter1_552_604_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_552_604_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_552_604_Open_Text">
										<span style="COLOR: #000000">{<br /></span>
										<span style="COLOR: #008080">25</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            buffer[iWritePos</span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000">] </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> s[iRevTokenScanner</span>
										<span style="COLOR: #000000">--</span>
										<span style="COLOR: #000000">];<br /></span>
										<span style="COLOR: #008080">26</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000"> <br /></span>
								<span style="COLOR: #008080">27</span>
								<span style="COLOR: #000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
						</span>
						<span style="COLOR: #008080">28</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
						</span>
						<span style="COLOR: #008080">29</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    buffer[iWritePos] </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">'</span>
						<span style="COLOR: #000000">\0</span>
						<span style="COLOR: #000000">'</span>
						<span style="COLOR: #000000">;<br /></span>
						<span style="COLOR: #008080">30</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    strcpy(s, buffer);<br /></span>
						<span style="COLOR: #008080">31</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
						</span>
						<span style="COLOR: #008080">32</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (buffer)<br /></span>
						<span style="COLOR: #008080">33</span>
						<span style="COLOR: #000000">
								<img id="Codehighlighter1_674_711_Open_Image" onclick="this.style.display='none'; Codehighlighter1_674_711_Open_Text.style.display='none'; Codehighlighter1_674_711_Closed_Image.style.display='inline'; Codehighlighter1_674_711_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_674_711_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_674_711_Closed_Text.style.display='none'; Codehighlighter1_674_711_Open_Image.style.display='inline'; Codehighlighter1_674_711_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_674_711_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_674_711_Open_Text">
								<span style="COLOR: #000000">{<br /></span>
								<span style="COLOR: #008080">34</span>
								<span style="COLOR: #000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        delete [] buffer;<br /></span>
								<span style="COLOR: #008080">35</span>
								<span style="COLOR: #000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        buffer </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">;<br /></span>
								<span style="COLOR: #008080">36</span>
								<span style="COLOR: #000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
						</span>
						<span style="COLOR: #008080">37</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
		<br />
		<font color="#0000ff" size="2">方法二，个人比较prefer<br /><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"> 1</span><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> ReverseString(</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">s, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> start, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> end)<br /></span><span style="COLOR: #008080"> 2</span><span style="COLOR: #000000"><img id="Codehighlighter1_48_205_Open_Image" onclick="this.style.display='none'; Codehighlighter1_48_205_Open_Text.style.display='none'; Codehighlighter1_48_205_Closed_Image.style.display='inline'; Codehighlighter1_48_205_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_48_205_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_48_205_Closed_Text.style.display='none'; Codehighlighter1_48_205_Open_Image.style.display='inline'; Codehighlighter1_48_205_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_48_205_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_48_205_Open_Text"><span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080"> 3</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> (start </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> end)<br /></span><span style="COLOR: #008080"> 4</span><span style="COLOR: #000000"><img id="Codehighlighter1_72_203_Open_Image" onclick="this.style.display='none'; Codehighlighter1_72_203_Open_Text.style.display='none'; Codehighlighter1_72_203_Closed_Image.style.display='inline'; Codehighlighter1_72_203_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_72_203_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_72_203_Closed_Text.style.display='none'; Codehighlighter1_72_203_Open_Image.style.display='inline'; Codehighlighter1_72_203_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_72_203_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_72_203_Open_Text"><span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080"> 5</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (s[start] </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> s[end])<br /></span><span style="COLOR: #008080"> 6</span><span style="COLOR: #000000"><img id="Codehighlighter1_102_175_Open_Image" onclick="this.style.display='none'; Codehighlighter1_102_175_Open_Text.style.display='none'; Codehighlighter1_102_175_Closed_Image.style.display='inline'; Codehighlighter1_102_175_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_102_175_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_102_175_Closed_Text.style.display='none'; Codehighlighter1_102_175_Open_Image.style.display='inline'; Codehighlighter1_102_175_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span id="Codehighlighter1_102_175_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_102_175_Open_Text"><span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080"> 7</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            s[start] </span><span style="COLOR: #000000">^=</span><span style="COLOR: #000000"> s[end];<br /></span><span style="COLOR: #008080"> 8</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            s[end] </span><span style="COLOR: #000000">^=</span><span style="COLOR: #000000"> s[start];<br /></span><span style="COLOR: #008080"> 9</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            s[start] </span><span style="COLOR: #000000">^=</span><span style="COLOR: #000000"> s[end];<br /></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                <br /></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        start</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        end</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /></span><span style="COLOR: #008080">17</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> ReverseByWords(</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">s, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> len, </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000"> seperator)<br /></span><span style="COLOR: #008080">18</span><span style="COLOR: #000000"><img id="Codehighlighter1_262_522_Open_Image" onclick="this.style.display='none'; Codehighlighter1_262_522_Open_Text.style.display='none'; Codehighlighter1_262_522_Closed_Image.style.display='inline'; Codehighlighter1_262_522_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_262_522_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_262_522_Closed_Text.style.display='none'; Codehighlighter1_262_522_Open_Image.style.display='inline'; Codehighlighter1_262_522_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_262_522_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_262_522_Open_Text"><span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">19</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> start </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">, end </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">20</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /></span><span style="COLOR: #008080">21</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    ReverseString(s, start, len </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008080">22</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /></span><span style="COLOR: #008080">23</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> (end </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> len)<br /></span><span style="COLOR: #008080">24</span><span style="COLOR: #000000"><img id="Codehighlighter1_346_513_Open_Image" onclick="this.style.display='none'; Codehighlighter1_346_513_Open_Text.style.display='none'; Codehighlighter1_346_513_Closed_Image.style.display='inline'; Codehighlighter1_346_513_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_346_513_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_346_513_Closed_Text.style.display='none'; Codehighlighter1_346_513_Open_Image.style.display='inline'; Codehighlighter1_346_513_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_346_513_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_346_513_Open_Text"><span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">25</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (s[end] </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> seperator)<br /></span><span style="COLOR: #008080">26</span><span style="COLOR: #000000"><img id="Codehighlighter1_377_497_Open_Image" onclick="this.style.display='none'; Codehighlighter1_377_497_Open_Text.style.display='none'; Codehighlighter1_377_497_Closed_Image.style.display='inline'; Codehighlighter1_377_497_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_377_497_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_377_497_Closed_Text.style.display='none'; Codehighlighter1_377_497_Open_Image.style.display='inline'; Codehighlighter1_377_497_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span id="Codehighlighter1_377_497_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_377_497_Open_Text"><span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">27</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            start </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> end;<br /></span><span style="COLOR: #008080">28</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /></span><span style="COLOR: #008080">29</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> (end </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> len </span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000"> s[end] </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> seperator)<br /></span><span style="COLOR: #008080">30</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                end</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">31</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            end</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">32</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /></span><span style="COLOR: #008080">33</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            ReverseString(s, start, end);<br /></span><span style="COLOR: #008080">34</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">35</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        <br /></span><span style="COLOR: #008080">36</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        end</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">37</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /></span><span style="COLOR: #008080">38</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">while</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">39</span><span style="COLOR: #008000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" /></span><span style="COLOR: #000000">}</span></span></div></font>
		<br />
		<font face="Verdana" color="#0000ff" size="2">等有空再回来作注释吧，现在挺忙的，先把code贴出来</font>
<img src ="http://www.cppblog.com/Winux32/aggbug/15253.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Winux32/" target="_blank">Charles</a> 2006-11-16 18:50 <a href="http://www.cppblog.com/Winux32/archive/2006/11/16/15253.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>字符串无回溯BM匹配算法</title><link>http://www.cppblog.com/Winux32/archive/2006/11/16/15251.html</link><dc:creator>Charles</dc:creator><author>Charles</author><pubDate>Thu, 16 Nov 2006 10:03:00 GMT</pubDate><guid>http://www.cppblog.com/Winux32/archive/2006/11/16/15251.html</guid><wfw:comment>http://www.cppblog.com/Winux32/comments/15251.html</wfw:comment><comments>http://www.cppblog.com/Winux32/archive/2006/11/16/15251.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/Winux32/comments/commentRss/15251.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Winux32/services/trackbacks/15251.html</trackback:ping><description><![CDATA[
		<font face="Verdana" color="#0000ff">
				<font size="2">接着来个无回溯的，一般教科书上都是用KMP作case的，这里给个平均效率更好的Boyer-Moore Algorithm实现<br /></font>
				<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">
						<font size="2">
								<span style="COLOR: #008080"> 1</span>
								<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
								<span style="COLOR: #000000">#include </span>
								<span style="COLOR: #000000">&lt;</span>
								<span style="COLOR: #000000">cstring</span>
								<span style="COLOR: #000000">&gt;</span>
						</font>
						<span style="COLOR: #000000">
								<br />
						</span>
						<font size="2">
								<span style="COLOR: #008080"> 2</span>
								<span style="COLOR: #000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
								</span>
								<span style="COLOR: #0000ff">int</span>
								<span style="COLOR: #000000"> BM(</span>
								<span style="COLOR: #0000ff">const</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">char</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">text, </span>
								<span style="COLOR: #0000ff">const</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">char</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">*</span>
						</font>
						<font size="2">
								<span style="COLOR: #000000">pattern)<br /></span>
								<span style="COLOR: #008080"> 3</span>
								<span style="COLOR: #000000">
										<img id="Codehighlighter1_65_758_Open_Image" onclick="this.style.display='none'; Codehighlighter1_65_758_Open_Text.style.display='none'; Codehighlighter1_65_758_Closed_Image.style.display='inline'; Codehighlighter1_65_758_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
										<img id="Codehighlighter1_65_758_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_65_758_Closed_Text.style.display='none'; Codehighlighter1_65_758_Open_Image.style.display='inline'; Codehighlighter1_65_758_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
								</span>
								<span id="Codehighlighter1_65_758_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
						</font>
						<span id="Codehighlighter1_65_758_Open_Text">
								<font size="2">
										<span style="COLOR: #000000">{<br /></span>
										<span style="COLOR: #008080"> 4</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
										<span style="COLOR: #0000ff">int</span>
										<span style="COLOR: #000000"> arrShiftTable[</span>
										<span style="COLOR: #000000">256</span>
								</font>
								<font size="2">
										<span style="COLOR: #000000">];<br /></span>
										<span style="COLOR: #008080"> 5</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
										<span style="COLOR: #0000ff">int</span>
										<span style="COLOR: #000000"> tLen </span>
										<span style="COLOR: #000000">=</span>
								</font>
								<font size="2">
										<span style="COLOR: #000000"> strlen(text);<br /></span>
										<span style="COLOR: #008080"> 6</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
										<span style="COLOR: #0000ff">int</span>
										<span style="COLOR: #000000"> pLen </span>
										<span style="COLOR: #000000">=</span>
								</font>
								<font size="2">
										<span style="COLOR: #000000"> strlen(pattern);<br /></span>
										<span style="COLOR: #008080"> 7</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
										<span style="COLOR: #0000ff">int</span>
								</font>
								<font size="2">
										<span style="COLOR: #000000"> currPos, tReadPos, pReadPos;<br /></span>
										<span style="COLOR: #008080"> 8</span>
								</font>
								<font size="2">
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
												<br />
										</span>
										<span style="COLOR: #008080"> 9</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">exclude NUL</span>
								</font>
								<span style="COLOR: #008000">
										<br />
								</span>
								<font size="2">
										<span style="COLOR: #008080">10</span>
										<span style="COLOR: #008000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
										</span>
										<span style="COLOR: #000000">    </span>
										<span style="COLOR: #0000ff">for</span>
										<span style="COLOR: #000000"> (</span>
										<span style="COLOR: #0000ff">int</span>
										<span style="COLOR: #000000"> i </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">; i </span>
										<span style="COLOR: #000000">&lt;</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">sizeof</span>
										<span style="COLOR: #000000"> arrShiftTable </span>
										<span style="COLOR: #000000">/</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">sizeof</span>
										<span style="COLOR: #000000"> (</span>
										<span style="COLOR: #0000ff">int</span>
										<span style="COLOR: #000000">); i</span>
										<span style="COLOR: #000000">++</span>
								</font>
								<font size="2">
										<span style="COLOR: #000000">)<br /></span>
										<span style="COLOR: #008080">11</span>
										<span style="COLOR: #000000">
												<img id="Codehighlighter1_261_291_Open_Image" onclick="this.style.display='none'; Codehighlighter1_261_291_Open_Text.style.display='none'; Codehighlighter1_261_291_Closed_Image.style.display='inline'; Codehighlighter1_261_291_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
												<img id="Codehighlighter1_261_291_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_261_291_Closed_Text.style.display='none'; Codehighlighter1_261_291_Open_Image.style.display='inline'; Codehighlighter1_261_291_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
										<span id="Codehighlighter1_261_291_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
								</font>
								<span id="Codehighlighter1_261_291_Open_Text">
										<font size="2">
												<span style="COLOR: #000000">{<br /></span>
												<span style="COLOR: #008080">12</span>
												<span style="COLOR: #000000">
														<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        arrShiftTable[i] </span>
												<span style="COLOR: #000000">=</span>
										</font>
										<font size="2">
												<span style="COLOR: #000000"> pLen;<br /></span>
												<span style="COLOR: #008080">13</span>
												<span style="COLOR: #000000">
														<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
										</font>
								</span>
								<span style="COLOR: #000000">
										<br />
								</span>
								<span style="COLOR: #008080">
										<font size="2">14</font>
								</span>
								<font size="2">
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
												<br />
										</span>
										<span style="COLOR: #008080">15</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">exclude the last char in pattern</span>
								</font>
								<span style="COLOR: #008000">
										<br />
								</span>
								<font size="2">
										<span style="COLOR: #008080">16</span>
										<span style="COLOR: #008000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
										</span>
										<span style="COLOR: #000000">    </span>
										<span style="COLOR: #0000ff">for</span>
										<span style="COLOR: #000000"> (</span>
										<span style="COLOR: #0000ff">int</span>
										<span style="COLOR: #000000"> i </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">; i </span>
										<span style="COLOR: #000000">&lt;</span>
										<span style="COLOR: #000000"> pLen </span>
										<span style="COLOR: #000000">-</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">; i</span>
										<span style="COLOR: #000000">++</span>
								</font>
								<font size="2">
										<span style="COLOR: #000000">)<br /></span>
										<span style="COLOR: #008080">17</span>
										<span style="COLOR: #000000">
												<img id="Codehighlighter1_367_414_Open_Image" onclick="this.style.display='none'; Codehighlighter1_367_414_Open_Text.style.display='none'; Codehighlighter1_367_414_Closed_Image.style.display='inline'; Codehighlighter1_367_414_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
												<img id="Codehighlighter1_367_414_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_367_414_Closed_Text.style.display='none'; Codehighlighter1_367_414_Open_Image.style.display='inline'; Codehighlighter1_367_414_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
										<span id="Codehighlighter1_367_414_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
								</font>
								<span id="Codehighlighter1_367_414_Open_Text">
										<font size="2">
												<span style="COLOR: #000000">{<br /></span>
												<span style="COLOR: #008080">18</span>
												<span style="COLOR: #000000">
														<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        arrShiftTable[pattern[i]] </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> pLen </span>
												<span style="COLOR: #000000">-</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">1</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">-</span>
										</font>
										<font size="2">
												<span style="COLOR: #000000"> i;<br /></span>
												<span style="COLOR: #008080">19</span>
												<span style="COLOR: #000000">
														<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
										</font>
								</span>
								<span style="COLOR: #000000">
										<br />
								</span>
								<span style="COLOR: #008080">
										<font size="2">20</font>
								</span>
								<font size="2">
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
												<br />
										</span>
										<span style="COLOR: #008080">21</span>
										<span style="COLOR: #000000">
												<img id="Codehighlighter1_459_466_Open_Image" onclick="this.style.display='none'; Codehighlighter1_459_466_Open_Text.style.display='none'; Codehighlighter1_459_466_Closed_Image.style.display='inline'; Codehighlighter1_459_466_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
												<img id="Codehighlighter1_459_466_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_459_466_Closed_Text.style.display='none'; Codehighlighter1_459_466_Open_Image.style.display='inline'; Codehighlighter1_459_466_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
										<span style="COLOR: #0000ff">for</span>
										<span style="COLOR: #000000"> (currPos </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> pLen </span>
										<span style="COLOR: #000000">-</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">; currPos </span>
										<span style="COLOR: #000000">&lt;</span>
										<span style="COLOR: #000000"> tLen; </span>
										<span id="Codehighlighter1_459_466_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span>
										<span id="Codehighlighter1_459_466_Open_Text">
												<span style="COLOR: #008000">/*</span>
												<span style="COLOR: #008000">null</span>
												<span style="COLOR: #008000">*/</span>
										</span>
								</font>
								<font size="2">
										<span style="COLOR: #000000">)<br /></span>
										<span style="COLOR: #008080">22</span>
										<span style="COLOR: #000000">
												<img id="Codehighlighter1_470_732_Open_Image" onclick="this.style.display='none'; Codehighlighter1_470_732_Open_Text.style.display='none'; Codehighlighter1_470_732_Closed_Image.style.display='inline'; Codehighlighter1_470_732_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
												<img id="Codehighlighter1_470_732_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_470_732_Closed_Text.style.display='none'; Codehighlighter1_470_732_Open_Image.style.display='inline'; Codehighlighter1_470_732_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
										<span id="Codehighlighter1_470_732_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
								</font>
								<span id="Codehighlighter1_470_732_Open_Text">
										<font size="2">
												<span style="COLOR: #000000">{<br /></span>
												<span style="COLOR: #008080">23</span>
												<span style="COLOR: #000000">
														<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
												<span style="COLOR: #0000ff">for</span>
												<span style="COLOR: #000000"> (pReadPos </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> pLen </span>
												<span style="COLOR: #000000">-</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">1</span>
												<span style="COLOR: #000000">, tReadPos </span>
												<span style="COLOR: #000000">=</span>
										</font>
										<font size="2">
												<span style="COLOR: #000000"> currPos;<br /></span>
												<span style="COLOR: #008080">24</span>
												<span style="COLOR: #000000">
														<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            pReadPos </span>
												<span style="COLOR: #000000">&gt;=</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">0</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">&amp;&amp;</span>
												<span style="COLOR: #000000"> pattern[pReadPos] </span>
												<span style="COLOR: #000000">==</span>
										</font>
										<font size="2">
												<span style="COLOR: #000000"> text[tReadPos];<br /></span>
												<span style="COLOR: #008080">25</span>
												<span style="COLOR: #000000">
														<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            pReadPos</span>
												<span style="COLOR: #000000">--</span>
												<span style="COLOR: #000000">, tReadPos</span>
												<span style="COLOR: #000000">--</span>
										</font>
										<font size="2">
												<span style="COLOR: #000000">)<br /></span>
												<span style="COLOR: #008080">26</span>
												<span style="COLOR: #000000">
														<img id="Codehighlighter1_607_614_Open_Image" onclick="this.style.display='none'; Codehighlighter1_607_614_Open_Text.style.display='none'; Codehighlighter1_607_614_Closed_Image.style.display='inline'; Codehighlighter1_607_614_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
														<img id="Codehighlighter1_607_614_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_607_614_Closed_Text.style.display='none'; Codehighlighter1_607_614_Open_Image.style.display='inline'; Codehighlighter1_607_614_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
												<span id="Codehighlighter1_607_614_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span>
												<span id="Codehighlighter1_607_614_Open_Text">
														<span style="COLOR: #008000">/*</span>
														<span style="COLOR: #008000">null</span>
														<span style="COLOR: #008000">*/</span>
												</span>
										</font>
										<font size="2">
												<span style="COLOR: #000000">;<br /></span>
												<span style="COLOR: #008080">27</span>
										</font>
										<font size="2">
												<span style="COLOR: #000000">
														<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
														<br />
												</span>
												<span style="COLOR: #008080">28</span>
												<span style="COLOR: #000000">
														<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
												<span style="COLOR: #0000ff">if</span>
												<span style="COLOR: #000000"> (pReadPos </span>
												<span style="COLOR: #000000">&lt;</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">0</span>
										</font>
										<font size="2">
												<span style="COLOR: #000000">)<br /></span>
												<span style="COLOR: #008080">29</span>
												<span style="COLOR: #000000">
														<img id="Codehighlighter1_640_668_Open_Image" onclick="this.style.display='none'; Codehighlighter1_640_668_Open_Text.style.display='none'; Codehighlighter1_640_668_Closed_Image.style.display='inline'; Codehighlighter1_640_668_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
														<img id="Codehighlighter1_640_668_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_640_668_Closed_Text.style.display='none'; Codehighlighter1_640_668_Open_Image.style.display='inline'; Codehighlighter1_640_668_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
												<span id="Codehighlighter1_640_668_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
														<img src="http://www.cppblog.com/images/dot.gif" />
												</span>
										</font>
										<span id="Codehighlighter1_640_668_Open_Text">
												<font size="2">
														<span style="COLOR: #000000">{<br /></span>
														<span style="COLOR: #008080">30</span>
														<span style="COLOR: #000000">
																<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
														<span style="COLOR: #0000ff">return</span>
														<span style="COLOR: #000000"> tReadPos </span>
														<span style="COLOR: #000000">+</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">1</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000">;<br /></span>
														<span style="COLOR: #008080">31</span>
														<span style="COLOR: #000000">
																<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
												</font>
										</span>
										<font size="2">
												<span style="COLOR: #000000"> <br /></span>
												<span style="COLOR: #008080">32</span>
												<span style="COLOR: #000000">
														<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
												<span style="COLOR: #0000ff">else</span>
										</font>
										<span style="COLOR: #000000">
												<br />
										</span>
										<font size="2">
												<span style="COLOR: #008080">33</span>
												<span style="COLOR: #000000">
														<img id="Codehighlighter1_680_728_Open_Image" onclick="this.style.display='none'; Codehighlighter1_680_728_Open_Text.style.display='none'; Codehighlighter1_680_728_Closed_Image.style.display='inline'; Codehighlighter1_680_728_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
														<img id="Codehighlighter1_680_728_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_680_728_Closed_Text.style.display='none'; Codehighlighter1_680_728_Open_Image.style.display='inline'; Codehighlighter1_680_728_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
												<span id="Codehighlighter1_680_728_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
														<img src="http://www.cppblog.com/images/dot.gif" />
												</span>
										</font>
										<span id="Codehighlighter1_680_728_Open_Text">
												<font size="2">
														<span style="COLOR: #000000">{<br /></span>
														<span style="COLOR: #008080">34</span>
														<span style="COLOR: #000000">
																<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            currPos </span>
														<span style="COLOR: #000000">+=</span>
												</font>
												<font size="2">
														<span style="COLOR: #000000"> arrShiftTable[text[currPos]];<br /></span>
														<span style="COLOR: #008080">35</span>
														<span style="COLOR: #000000">
																<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
												</font>
										</span>
										<span style="COLOR: #000000">
												<br />
										</span>
										<span style="COLOR: #008080">
												<font size="2">36</font>
										</span>
										<font size="2">
												<span style="COLOR: #000000">
														<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
														<br />
												</span>
												<span style="COLOR: #008080">37</span>
												<span style="COLOR: #000000">
														<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
										</font>
								</span>
								<font size="2">
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">outer for</span>
								</font>
								<span style="COLOR: #008000">
										<br />
								</span>
								<font size="2">
										<span style="COLOR: #008080">38</span>
										<span style="COLOR: #008000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
										</span>
								</font>
								<span style="COLOR: #000000">
										<br />
								</span>
								<font size="2">
										<span style="COLOR: #008080">39</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
										<span style="COLOR: #0000ff">return</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">-</span>
										<span style="COLOR: #000000">1</span>
								</font>
								<font size="2">
										<span style="COLOR: #000000">;<br /></span>
										<span style="COLOR: #008080">40</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
								</font>
						</span>
				</div>
		</font>
		<font color="#0000ff" size="2">算法原理就不细说了，有兴趣可以google一下，主要思想就是从模式串的最后一个字母向前比较。此处需要使用一个跳转表，以便查询不匹配时模式串前进的步数。</font>
<img src ="http://www.cppblog.com/Winux32/aggbug/15251.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Winux32/" target="_blank">Charles</a> 2006-11-16 18:03 <a href="http://www.cppblog.com/Winux32/archive/2006/11/16/15251.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>字符串回溯匹配算法</title><link>http://www.cppblog.com/Winux32/archive/2006/11/16/15249.html</link><dc:creator>Charles</dc:creator><author>Charles</author><pubDate>Thu, 16 Nov 2006 09:53:00 GMT</pubDate><guid>http://www.cppblog.com/Winux32/archive/2006/11/16/15249.html</guid><wfw:comment>http://www.cppblog.com/Winux32/comments/15249.html</wfw:comment><comments>http://www.cppblog.com/Winux32/archive/2006/11/16/15249.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Winux32/comments/commentRss/15249.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Winux32/services/trackbacks/15249.html</trackback:ping><description><![CDATA[
		<p>
				<font face="Verdana" color="#0000ff">这个虽然简单，效率也不高，但面试还是经常考的，试着写写看。Coding makes you exact</font>
		</p>
		<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"> 1</span>
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">const</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">char</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> MyStrStr(</span>
				<span style="COLOR: #0000ff">const</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">char</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">text, </span>
				<span style="COLOR: #0000ff">const</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">char</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">pattern)<br /></span>
				<span style="COLOR: #008080"> 2</span>
				<span style="COLOR: #000000">
						<img id="Codehighlighter1_60_296_Open_Image" onclick="this.style.display='none'; Codehighlighter1_60_296_Open_Text.style.display='none'; Codehighlighter1_60_296_Closed_Image.style.display='inline'; Codehighlighter1_60_296_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_60_296_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_60_296_Closed_Text.style.display='none'; Codehighlighter1_60_296_Open_Image.style.display='inline'; Codehighlighter1_60_296_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				</span>
				<span id="Codehighlighter1_60_296_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_60_296_Open_Text">
						<span style="COLOR: #000000">{<br /></span>
						<span style="COLOR: #008080"> 3</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">, j </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /></span>
						<span style="COLOR: #008080"> 4</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
						</span>
						<span style="COLOR: #008080"> 5</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">while</span>
						<span style="COLOR: #000000"> (pattern[i] </span>
						<span style="COLOR: #000000">&amp;&amp;</span>
						<span style="COLOR: #000000"> text[j])<br /></span>
						<span style="COLOR: #008080"> 6</span>
						<span style="COLOR: #000000">
								<img id="Codehighlighter1_114_214_Open_Image" onclick="this.style.display='none'; Codehighlighter1_114_214_Open_Text.style.display='none'; Codehighlighter1_114_214_Closed_Image.style.display='inline'; Codehighlighter1_114_214_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_114_214_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_114_214_Closed_Text.style.display='none'; Codehighlighter1_114_214_Open_Image.style.display='inline'; Codehighlighter1_114_214_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_114_214_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_114_214_Open_Text">
								<span style="COLOR: #000000">{<br /></span>
								<span style="COLOR: #008080"> 7</span>
								<span style="COLOR: #000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000"> (pattern[i] </span>
								<span style="COLOR: #000000">==</span>
								<span style="COLOR: #000000"> text[j])<br /></span>
								<span style="COLOR: #008080"> 8</span>
								<span style="COLOR: #000000">
										<img id="Codehighlighter1_147_167_Open_Image" onclick="this.style.display='none'; Codehighlighter1_147_167_Open_Text.style.display='none'; Codehighlighter1_147_167_Closed_Image.style.display='inline'; Codehighlighter1_147_167_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
										<img id="Codehighlighter1_147_167_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_147_167_Closed_Text.style.display='none'; Codehighlighter1_147_167_Open_Image.style.display='inline'; Codehighlighter1_147_167_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_147_167_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_147_167_Open_Text">
										<span style="COLOR: #000000">{<br /></span>
										<span style="COLOR: #008080"> 9</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000">i;<br /></span>
										<span style="COLOR: #008080">10</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000">j;<br /></span>
										<span style="COLOR: #008080">11</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000"> <br /></span>
								<span style="COLOR: #008080">12</span>
								<span style="COLOR: #000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">else</span>
								<span style="COLOR: #000000">
										<br />
								</span>
								<span style="COLOR: #008080">13</span>
								<span style="COLOR: #000000">
										<img id="Codehighlighter1_179_211_Open_Image" onclick="this.style.display='none'; Codehighlighter1_179_211_Open_Text.style.display='none'; Codehighlighter1_179_211_Closed_Image.style.display='inline'; Codehighlighter1_179_211_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
										<img id="Codehighlighter1_179_211_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_179_211_Closed_Text.style.display='none'; Codehighlighter1_179_211_Open_Image.style.display='inline'; Codehighlighter1_179_211_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_179_211_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_179_211_Open_Text">
										<span style="COLOR: #000000">{<br /></span>
										<span style="COLOR: #008080">14</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            i </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">;<br /></span>
										<span style="COLOR: #008080">15</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            j </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> j </span>
										<span style="COLOR: #000000">-</span>
										<span style="COLOR: #000000"> i </span>
										<span style="COLOR: #000000">+</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">;<br /></span>
										<span style="COLOR: #008080">16</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
								</span>
								<span style="COLOR: #008080">17</span>
								<span style="COLOR: #000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">while</span>
						<span style="COLOR: #008000">
								<br />
						</span>
						<span style="COLOR: #008080">18</span>
						<span style="COLOR: #008000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">
								<br />
						</span>
						<span style="COLOR: #008080">19</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (</span>
						<span style="COLOR: #000000">!</span>
						<span style="COLOR: #000000">pattern[i])<br /></span>
						<span style="COLOR: #008080">20</span>
						<span style="COLOR: #000000">
								<img id="Codehighlighter1_243_269_Open_Image" onclick="this.style.display='none'; Codehighlighter1_243_269_Open_Text.style.display='none'; Codehighlighter1_243_269_Closed_Image.style.display='inline'; Codehighlighter1_243_269_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_243_269_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_243_269_Closed_Text.style.display='none'; Codehighlighter1_243_269_Open_Image.style.display='inline'; Codehighlighter1_243_269_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_243_269_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_243_269_Open_Text">
								<span style="COLOR: #000000">{<br /></span>
								<span style="COLOR: #008080">21</span>
								<span style="COLOR: #000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> text </span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000"> j </span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000"> i;<br /></span>
								<span style="COLOR: #008080">22</span>
								<span style="COLOR: #000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000"> <br /></span>
						<span style="COLOR: #008080">23</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">else</span>
						<span style="COLOR: #000000">
								<br />
						</span>
						<span style="COLOR: #008080">24</span>
						<span style="COLOR: #000000">
								<img id="Codehighlighter1_279_294_Open_Image" onclick="this.style.display='none'; Codehighlighter1_279_294_Open_Text.style.display='none'; Codehighlighter1_279_294_Closed_Image.style.display='inline'; Codehighlighter1_279_294_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_279_294_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_279_294_Closed_Text.style.display='none'; Codehighlighter1_279_294_Open_Image.style.display='inline'; Codehighlighter1_279_294_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_279_294_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_279_294_Open_Text">
								<span style="COLOR: #000000">{<br /></span>
								<span style="COLOR: #008080">25</span>
								<span style="COLOR: #000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">;<br /></span>
								<span style="COLOR: #008080">26</span>
								<span style="COLOR: #000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
						</span>
						<span style="COLOR: #008080">27</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
		</div>
		<br />
		<font color="#0000ff">需要注意的地方是<font face="Verdana">line#15, line#21。j - i 表示之前前进的步数，+1表示从下个位置比较</font></font>
<img src ="http://www.cppblog.com/Winux32/aggbug/15249.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Winux32/" target="_blank">Charles</a> 2006-11-16 17:53 <a href="http://www.cppblog.com/Winux32/archive/2006/11/16/15249.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>写在前面的话</title><link>http://www.cppblog.com/Winux32/archive/2006/11/16/15246.html</link><dc:creator>Charles</dc:creator><author>Charles</author><pubDate>Thu, 16 Nov 2006 09:38:00 GMT</pubDate><guid>http://www.cppblog.com/Winux32/archive/2006/11/16/15246.html</guid><wfw:comment>http://www.cppblog.com/Winux32/comments/15246.html</wfw:comment><comments>http://www.cppblog.com/Winux32/archive/2006/11/16/15246.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Winux32/comments/commentRss/15246.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Winux32/services/trackbacks/15246.html</trackback:ping><description><![CDATA[
		<font face="Tahoma" color="#0000ff" size="2">把前段时间找工作时写的一些小函数贴出来，主要想做个备忘。如果对你有所启发，我会很高兴。<br />这篇帖子同时也是我在这里的第一篇文字，一直想写技术博客，苦于代码发布不便利，今天偶然路过这里觉得还不错，于是决定把家定在这里，希望看我的文字会给你带来乐趣</font>
<img src ="http://www.cppblog.com/Winux32/aggbug/15246.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Winux32/" target="_blank">Charles</a> 2006-11-16 17:38 <a href="http://www.cppblog.com/Winux32/archive/2006/11/16/15246.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>