﻿<?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++博客-技术，瞎侃，健康，休闲……-随笔分类-C/C++</title><link>http://www.cppblog.com/mahudu/category/1924.html</link><description>mahu@cppblog
       人类的全部才能无非是时间和耐心的混合物</description><language>zh-cn</language><lastBuildDate>Tue, 20 May 2008 17:47:01 GMT</lastBuildDate><pubDate>Tue, 20 May 2008 17:47:01 GMT</pubDate><ttl>60</ttl><item><title>一个虚函数的访问权限问题</title><link>http://www.cppblog.com/mahudu/archive/2006/06/28/9100.html</link><dc:creator>mahudu@cppblog</dc:creator><author>mahudu@cppblog</author><pubDate>Wed, 28 Jun 2006 03:42:00 GMT</pubDate><guid>http://www.cppblog.com/mahudu/archive/2006/06/28/9100.html</guid><wfw:comment>http://www.cppblog.com/mahudu/comments/9100.html</wfw:comment><comments>http://www.cppblog.com/mahudu/archive/2006/06/28/9100.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/mahudu/comments/commentRss/9100.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mahudu/services/trackbacks/9100.html</trackback:ping><description><![CDATA[在水木上见到一个贴子，关于虚函数的访问权限问题：<br /><span lang="EN-US" style="FONT-FAMILY: 'Courier New'"><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"></p></span><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /?><o:p></o: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">cstdlib</span><span style="COLOR: #000000">&gt;</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" />#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</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">using</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000"> std;<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" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_72_261_Open_Image" onclick="this.style.display='none'; Codehighlighter1_72_261_Open_Text.style.display='none'; Codehighlighter1_72_261_Closed_Image.style.display='inline'; Codehighlighter1_72_261_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_72_261_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_72_261_Closed_Text.style.display='none'; Codehighlighter1_72_261_Open_Image.style.display='inline'; Codehighlighter1_72_261_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> B </span><span id="Codehighlighter1_72_261_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_261_Open_Text"><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 src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img id="Codehighlighter1_103_135_Open_Image" onclick="this.style.display='none'; Codehighlighter1_103_135_Open_Text.style.display='none'; Codehighlighter1_103_135_Closed_Image.style.display='inline'; Codehighlighter1_103_135_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_103_135_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_103_135_Closed_Text.style.display='none'; Codehighlighter1_103_135_Open_Image.style.display='inline'; Codehighlighter1_103_135_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />   </span><span style="COLOR: #0000ff">virtual</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> f1()</span><span id="Codehighlighter1_103_135_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_135_Open_Text"><span style="COLOR: #000000">{cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">B::f1()</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;</span><span style="COLOR: #0000ff">return</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 id="Codehighlighter1_166_192_Open_Image" onclick="this.style.display='none'; Codehighlighter1_166_192_Open_Text.style.display='none'; Codehighlighter1_166_192_Closed_Image.style.display='inline'; Codehighlighter1_166_192_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_166_192_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_166_192_Closed_Text.style.display='none'; Codehighlighter1_166_192_Open_Image.style.display='inline'; Codehighlighter1_166_192_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />   </span><span style="COLOR: #0000ff">virtual</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> f2( </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> val)</span><span id="Codehighlighter1_166_192_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_166_192_Open_Text"><span style="COLOR: #000000">{cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">B::f2(int)</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;}</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img id="Codehighlighter1_223_258_Open_Image" onclick="this.style.display='none'; Codehighlighter1_223_258_Open_Text.style.display='none'; Codehighlighter1_223_258_Closed_Image.style.display='inline'; Codehighlighter1_223_258_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_223_258_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_223_258_Closed_Text.style.display='none'; Codehighlighter1_223_258_Open_Image.style.display='inline'; Codehighlighter1_223_258_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />   </span><span style="COLOR: #0000ff">virtual</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> f3( </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> val )</span><span id="Codehighlighter1_223_258_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_223_258_Open_Text"><span style="COLOR: #000000">{cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">B::f3(int)</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;</span><span style="COLOR: #0000ff">return</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/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" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_287_438_Open_Image" onclick="this.style.display='none'; Codehighlighter1_287_438_Open_Text.style.display='none'; Codehighlighter1_287_438_Closed_Image.style.display='inline'; Codehighlighter1_287_438_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_287_438_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_287_438_Closed_Text.style.display='none'; Codehighlighter1_287_438_Open_Image.style.display='inline'; Codehighlighter1_287_438_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> D : </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> B </span><span id="Codehighlighter1_287_438_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_287_438_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img id="Codehighlighter1_301_333_Open_Image" onclick="this.style.display='none'; Codehighlighter1_301_333_Open_Text.style.display='none'; Codehighlighter1_301_333_Closed_Image.style.display='inline'; Codehighlighter1_301_333_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_301_333_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_301_333_Closed_Text.style.display='none'; Codehighlighter1_301_333_Open_Image.style.display='inline'; Codehighlighter1_301_333_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />   </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> f1()</span><span id="Codehighlighter1_301_333_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_301_333_Open_Text"><span style="COLOR: #000000">{cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">D::f1()</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;</span><span style="COLOR: #0000ff">return</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 id="Codehighlighter1_356_379_Open_Image" onclick="this.style.display='none'; Codehighlighter1_356_379_Open_Text.style.display='none'; Codehighlighter1_356_379_Closed_Image.style.display='inline'; Codehighlighter1_356_379_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_356_379_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_356_379_Closed_Text.style.display='none'; Codehighlighter1_356_379_Open_Image.style.display='inline'; Codehighlighter1_356_379_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />   </span><span style="COLOR: #0000ff">virtual</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> f4()</span><span id="Codehighlighter1_356_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_356_379_Open_Text"><span style="COLOR: #000000">{cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">D::f4()</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;}</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img id="Codehighlighter1_400_435_Open_Image" onclick="this.style.display='none'; Codehighlighter1_400_435_Open_Text.style.display='none'; Codehighlighter1_400_435_Closed_Image.style.display='inline'; Codehighlighter1_400_435_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_400_435_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_400_435_Closed_Text.style.display='none'; Codehighlighter1_400_435_Open_Image.style.display='inline'; Codehighlighter1_400_435_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />   </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> f3(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> val)</span><span id="Codehighlighter1_400_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><span id="Codehighlighter1_400_435_Open_Text"><span style="COLOR: #000000">{cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">D::f3(int)</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;</span><span style="COLOR: #0000ff">return</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/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" /> <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"> main(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> argc, </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">argv[])<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_479_642_Open_Image" onclick="this.style.display='none'; Codehighlighter1_479_642_Open_Text.style.display='none'; Codehighlighter1_479_642_Closed_Image.style.display='inline'; Codehighlighter1_479_642_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_479_642_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_479_642_Closed_Text.style.display='none'; Codehighlighter1_479_642_Open_Image.style.display='inline'; Codehighlighter1_479_642_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_479_642_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_479_642_Open_Text"><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" />   B </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">bp </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> D;<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" />   bp</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">f3(</span><span style="COLOR: #000000">12</span><span style="COLOR: #000000">);</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">D中的f3是private的，可以访问#1</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" />   D </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">dp</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> D;<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" />   dp</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">f3(</span><span style="COLOR: #000000">12</span><span style="COLOR: #000000">);</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">f3是private,访问不了，编译通不过</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" />   system(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">PAUSE</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">return</span><span style="COLOR: #000000"> EXIT_SUCCESS;<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><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span></div><br />其实这是一个关于访问权限决定时间的问题，由于<u>访问权限是编译时间决定的</u>，而不是运行时决定的。<br />B *bp = new D;  // 此时bp所指向的类型是B而不是D，而B的f3()是公有的，所以可以访问。<br />D *dp = new D; // 此时dp所指向的类型是D，而D的f3()是私有的，所以不能访问。<br /><img src ="http://www.cppblog.com/mahudu/aggbug/9100.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mahudu/" target="_blank">mahudu@cppblog</a> 2006-06-28 11:42 <a href="http://www.cppblog.com/mahudu/archive/2006/06/28/9100.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Self Numbers</title><link>http://www.cppblog.com/mahudu/archive/2006/06/16/8653.html</link><dc:creator>mahudu@cppblog</dc:creator><author>mahudu@cppblog</author><pubDate>Fri, 16 Jun 2006 15:32:00 GMT</pubDate><guid>http://www.cppblog.com/mahudu/archive/2006/06/16/8653.html</guid><wfw:comment>http://www.cppblog.com/mahudu/comments/8653.html</wfw:comment><comments>http://www.cppblog.com/mahudu/archive/2006/06/16/8653.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mahudu/comments/commentRss/8653.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mahudu/services/trackbacks/8653.html</trackback:ping><description><![CDATA[    <br /><p><font face="Verdana">In 1949 the Indian mathematician D.R. Kaprekar discovered a class</font></p><p><font face="Verdana">of numbers called self-numbers. For any positive integer n, define</font></p><p><font face="Verdana">d(n) to be n plus the sum of the digits of n. (The d stands</font></p><p><font face="Verdana">for digitadition, a term coined by Kaprekar.) For example, d(75) = 75 + 7 + 5 = 87. Given any positive integer n as a starting</font></p><p><font face="Verdana">point, you can construct the infinite increasing sequence of integers</font></p><p><font face="Verdana">n, d(n), d(d(n)), d(d(d(n))), .... For example, if you start with</font></p><p><font face="Verdana">33, the next number is 33 + 3 + 3 = 39, the next is 39 + 3 + 9 = 51, the next</font></p><p><font face="Verdana">is 51 + 5 + 1 = 57, and so you generate the sequence</font></p><p><font face="Verdana">33, 39, 51, 57, 69, 84, 96, 111, 114, 120, 123, 129, 141, ...</font></p><p><font face="Verdana">The number n is called a generator of d(n). In the</font></p><p><font face="Verdana">sequence above, 33 is a generator of 39, 39 is a generator of 51, 51</font></p><p><font face="Verdana">is a generator of 57, and so on. Some numbers have more than one</font></p><p><font face="Verdana">generator: for example, 101 has two generators, 91 and 100. A number</font></p><p><font face="Verdana">with no generators is a self-number. There are thirteen</font></p><p><font face="Verdana">self-numbers less than 100: 1, 3, 5, 7, 9, 20, 31, 42, 53, 64, 75, 86,</font></p><p><font face="Verdana">and 97.</font></p><p><font face="Verdana">Write a program to output all positive self-numbers less than 10000</font></p><p><font face="Verdana">in increasing order, one per line.</font></p><pre><h2 style="COLOR: rgb(26,92,200)">Output</h2><blockquote><pre><font face="Arial">1<br />3<br />5<br />7<br />9<br />20<br />31<br />42<br />53<br />64<br /> |<br /> |       &lt;-- a lot more numbers<br /> |<br />9903<br />9914<br />9925<br />9927<br />9938<br />9949<br />9960<br />9971<br />9982<br />9993</font><br /></pre></blockquote></pre><h2 style="COLOR: rgb(26,92,200)">Solution</h2><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">iostream</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"> </span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000"> std;<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">const</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000"> N </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">10000</span><span style="COLOR: #000000">;     </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">最大自然数</span><span style="COLOR: #008000"><br /><img id="Codehighlighter1_94_96_Open_Image" onclick="this.style.display='none'; Codehighlighter1_94_96_Open_Text.style.display='none'; Codehighlighter1_94_96_Closed_Image.style.display='inline'; Codehighlighter1_94_96_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_94_96_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_94_96_Closed_Text.style.display='none'; Codehighlighter1_94_96_Open_Image.style.display='inline'; Codehighlighter1_94_96_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000"> Arr[N </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">9</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span id="Codehighlighter1_94_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_94_96_Open_Text"><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">}</span></span><span style="COLOR: #000000">;   </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">是否是被排除的数字？ +9*4是为了要再多放4位数</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000"> DealNum(</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000"> n)<br /><img id="Codehighlighter1_151_238_Open_Image" onclick="this.style.display='none'; Codehighlighter1_151_238_Open_Text.style.display='none'; Codehighlighter1_151_238_Closed_Image.style.display='inline'; Codehighlighter1_151_238_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_151_238_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_151_238_Closed_Text.style.display='none'; Codehighlighter1_151_238_Open_Image.style.display='inline'; Codehighlighter1_151_238_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_151_238_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_151_238_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000"> sum </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">while</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 id="Codehighlighter1_188_222_Open_Image" onclick="this.style.display='none'; Codehighlighter1_188_222_Open_Text.style.display='none'; Codehighlighter1_188_222_Closed_Image.style.display='inline'; Codehighlighter1_188_222_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_188_222_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_188_222_Closed_Text.style.display='none'; Codehighlighter1_188_222_Open_Image.style.display='inline'; Codehighlighter1_188_222_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />  </span><span id="Codehighlighter1_188_222_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_188_222_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    sum </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> n</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" />    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/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">return</span><span style="COLOR: #000000"> sum;<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"> main()<br /><img id="Codehighlighter1_252_406_Open_Image" onclick="this.style.display='none'; Codehighlighter1_252_406_Open_Text.style.display='none'; Codehighlighter1_252_406_Closed_Image.style.display='inline'; Codehighlighter1_252_406_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_252_406_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_252_406_Closed_Text.style.display='none'; Codehighlighter1_252_406_Open_Image.style.display='inline'; Codehighlighter1_252_406_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_252_406_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_252_406_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"> 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">(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_290_319_Open_Image" onclick="this.style.display='none'; Codehighlighter1_290_319_Open_Text.style.display='none'; Codehighlighter1_290_319_Closed_Image.style.display='inline'; Codehighlighter1_290_319_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_290_319_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_290_319_Closed_Text.style.display='none'; Codehighlighter1_290_319_Open_Image.style.display='inline'; Codehighlighter1_290_319_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />  </span><span id="Codehighlighter1_290_319_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_290_319_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Arr[DealNum(i)] </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" />  </span><span style="COLOR: #0000ff">for</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_348_392_Open_Image" onclick="this.style.display='none'; Codehighlighter1_348_392_Open_Text.style.display='none'; Codehighlighter1_348_392_Closed_Image.style.display='inline'; Codehighlighter1_348_392_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_348_392_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_348_392_Closed_Text.style.display='none'; Codehighlighter1_348_392_Open_Image.style.display='inline'; Codehighlighter1_348_392_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />  </span><span id="Codehighlighter1_348_392_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_348_392_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">Arr[i])<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<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">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/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span></div><br /><pre></pre><img src ="http://www.cppblog.com/mahudu/aggbug/8653.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mahudu/" target="_blank">mahudu@cppblog</a> 2006-06-16 23:32 <a href="http://www.cppblog.com/mahudu/archive/2006/06/16/8653.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Booklet Printing</title><link>http://www.cppblog.com/mahudu/archive/2006/06/16/8652.html</link><dc:creator>mahudu@cppblog</dc:creator><author>mahudu@cppblog</author><pubDate>Fri, 16 Jun 2006 15:26:00 GMT</pubDate><guid>http://www.cppblog.com/mahudu/archive/2006/06/16/8652.html</guid><wfw:comment>http://www.cppblog.com/mahudu/comments/8652.html</wfw:comment><comments>http://www.cppblog.com/mahudu/archive/2006/06/16/8652.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mahudu/comments/commentRss/8652.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mahudu/services/trackbacks/8652.html</trackback:ping><description><![CDATA[    <br /><p>When printing out a document, normally the first page is printed first, then the second, then the third, and so on until the end. However, when creating a fold-over booklet, the order of printing must be altered. A fold-over booklet has four pages per sheet, with two on the front and two on the back. When you stack all the sheets in order, then fold the booklet in half, the pages appear in the correct order as in a regular book. </p><p>For example, a 4-page booklet would print on 1 sheet of paper: the front will contain page 4 then page 1, and the back will contain page 2 then page 3. </p><p></p><pre>                       Front              Back<br />                       -------------      -------------<br />                       |     |     |      |     |     |<br />                       |  4  |  1  |      |  2  |  3  |<br />                       |     |     |      |     |     |<br />                       -------------      -------------<br /></pre><p>Your task is to write a program that takes as input the number of pages to be printed, then generates the printing order. </p><p></p><h2><font color="#0070e8"><a name="SECTION0001001000000000000000">Input</a> </font></h2>The input file contains one or more test cases, followed by a line containing the number 0 that indicates the end of the file. 
<p>Each test case consists of a positive integer <i>n</i> on a line by itself, where <i>n</i> is the number of pages to be printed; <i>n</i> will not exceed 100. </p><p></p><h2><font color="#0070e8"><a name="SECTION0001002000000000000000">Output</a> </font></h2>For each test case, output a report indicating which pages should be printed on each sheet, exactly as shown in the example. If the desired number of pages does not completely fill up a sheet, then print the word <tt>Blank</tt> in place of a number. If the front or back of a sheet is entirely blank, do not generate output for that side of the sheet. 
<p>Output must be in ascending order by sheet, front first, then back. </p><p></p><h2><font color="#0070e8"><a name="SECTION0001003000000000000000">Sample Input</a> </font></h2><p></p><pre>1<br />14<br />4<br />0<br /></pre><p></p><h2><font color="#0070e8"><a name="SECTION0001004000000000000000">Sample Output</a> </font></h2><pre>Printing order for 1 pages:<br />Sheet 1, front: Blank, 1<br />Printing order for 14 pages:<br />Sheet 1, front: Blank, 1<br />Sheet 1, back : 2, Blank<br />Sheet 2, front: 14, 3<br />Sheet 2, back : 4, 13<br />Sheet 3, front: 12, 5<br />Sheet 3, back : 6, 11<br />Sheet 4, front: 10, 7<br />Sheet 4, back : 8, 9<br />Printing order for 4 pages:<br />Sheet 1, front: 4, 1<br />Sheet 1, back : 2, 3<br /><br /></pre><h2><font size="+0"><font color="#0070e8"><a name="SECTION0001004000000000000000">Solution</a></font></font></h2><h2><font size="+0"><font color="#0070e8"><a name="SECTION0001004000000000000000"></a></font></font></h2><pre><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">iostream</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"> </span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000"> std;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">#define</span><span style="COLOR: #000000"> PAGES 100</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_79_99_Open_Image" onclick="this.style.display='none'; Codehighlighter1_79_99_Open_Text.style.display='none'; Codehighlighter1_79_99_Closed_Image.style.display='inline'; Codehighlighter1_79_99_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_79_99_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_79_99_Closed_Text.style.display='none'; Codehighlighter1_79_99_Open_Image.style.display='inline'; Codehighlighter1_79_99_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />typedef </span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000"> side</span><span id="Codehighlighter1_79_99_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_79_99_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"> left,right;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000">side;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_127_155_Open_Image" onclick="this.style.display='none'; Codehighlighter1_127_155_Open_Text.style.display='none'; Codehighlighter1_127_155_Closed_Image.style.display='inline'; Codehighlighter1_127_155_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_127_155_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_127_155_Closed_Text.style.display='none'; Codehighlighter1_127_155_Open_Image.style.display='inline'; Codehighlighter1_127_155_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />typedef </span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000"> sheet</span><span id="Codehighlighter1_127_155_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_127_155_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    side front;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    side back;    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000">sheet;<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"> numSides;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />sheet sheets[PAGES];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_229_1699_Open_Image" onclick="this.style.display='none'; Codehighlighter1_229_1699_Open_Text.style.display='none'; Codehighlighter1_229_1699_Closed_Image.style.display='inline'; Codehighlighter1_229_1699_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_229_1699_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_229_1699_Closed_Text.style.display='none'; Codehighlighter1_229_1699_Open_Image.style.display='inline'; Codehighlighter1_229_1699_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> PrintPages(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> numSides)</span><span id="Codehighlighter1_229_1699_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_229_1699_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"> numSidesNew;    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> add,pages;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    add </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> numSides</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">;<br /><img id="Codehighlighter1_298_364_Open_Image" onclick="this.style.display='none'; Codehighlighter1_298_364_Open_Text.style.display='none'; Codehighlighter1_298_364_Closed_Image.style.display='inline'; Codehighlighter1_298_364_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_298_364_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_298_364_Closed_Text.style.display='none'; Codehighlighter1_298_364_Open_Image.style.display='inline'; Codehighlighter1_298_364_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(add </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)</span><span id="Codehighlighter1_298_364_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_298_364_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        numSidesNew </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> numSides </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"> add;    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 增加后的总面数,numSides为实际的总面数</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 src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        numSidesNew </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> numSides;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    pages </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> numSidesNew </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: #008000">//</span><span style="COLOR: #008000"> 总纸张数</span><span style="COLOR: #008000"><br /><img id="Codehighlighter1_463_951_Open_Image" onclick="this.style.display='none'; Codehighlighter1_463_951_Open_Text.style.display='none'; Codehighlighter1_463_951_Closed_Image.style.display='inline'; Codehighlighter1_463_951_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_463_951_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_463_951_Closed_Text.style.display='none'; Codehighlighter1_463_951_Open_Image.style.display='inline'; Codehighlighter1_463_951_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.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"> pages; i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)</span><span id="Codehighlighter1_463_951_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_463_951_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        sheets[i].front.left </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> numSidesNew </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">i;<br /><img id="Codehighlighter1_546_592_Open_Image" onclick="this.style.display='none'; Codehighlighter1_546_592_Open_Text.style.display='none'; Codehighlighter1_546_592_Closed_Image.style.display='inline'; Codehighlighter1_546_592_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_546_592_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_546_592_Closed_Text.style.display='none'; Codehighlighter1_546_592_Open_Image.style.display='inline'; Codehighlighter1_546_592_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(sheets[i].front.left </span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> numSides)</span><span id="Codehighlighter1_546_592_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_546_592_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            sheets[i].front.left </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: #008000">//</span><span style="COLOR: #008000"> 表明应为blank</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" />        sheets[i].front.right </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">i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br /><img id="Codehighlighter1_665_712_Open_Image" onclick="this.style.display='none'; Codehighlighter1_665_712_Open_Text.style.display='none'; Codehighlighter1_665_712_Closed_Image.style.display='inline'; Codehighlighter1_665_712_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_665_712_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_665_712_Closed_Text.style.display='none'; Codehighlighter1_665_712_Open_Image.style.display='inline'; Codehighlighter1_665_712_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(sheets[i].front.right </span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> numSides)</span><span id="Codehighlighter1_665_712_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_665_712_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            sheets[i].front.right </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: #008000">//</span><span style="COLOR: #008000"> 表明应为blank</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" />        sheets[i].back.left </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">(i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br /><img id="Codehighlighter1_783_828_Open_Image" onclick="this.style.display='none'; Codehighlighter1_783_828_Open_Text.style.display='none'; Codehighlighter1_783_828_Closed_Image.style.display='inline'; Codehighlighter1_783_828_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_783_828_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_783_828_Closed_Text.style.display='none'; Codehighlighter1_783_828_Open_Image.style.display='inline'; Codehighlighter1_783_828_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(sheets[i].back.left </span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> numSides)</span><span id="Codehighlighter1_783_828_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_783_828_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            sheets[i].back.left </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: #008000">//</span><span style="COLOR: #008000"> 表明应为blank</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" />        sheets[i].back.right </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> numSidesNew </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">i </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_915_948_Open_Image" onclick="this.style.display='none'; Codehighlighter1_915_948_Open_Text.style.display='none'; Codehighlighter1_915_948_Closed_Image.style.display='inline'; Codehighlighter1_915_948_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_915_948_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_915_948_Closed_Text.style.display='none'; Codehighlighter1_915_948_Open_Image.style.display='inline'; Codehighlighter1_915_948_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(sheets[i].back.right </span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> numSides)</span><span id="Codehighlighter1_915_948_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_915_948_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            sheets[i].back.right </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/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" />    cout </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Printing order for </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> numSides </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> pages:</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> endl;<br /><img id="Codehighlighter1_1050_1697_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1050_1697_Open_Text.style.display='none'; Codehighlighter1_1050_1697_Closed_Image.style.display='inline'; Codehighlighter1_1050_1697_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1050_1697_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1050_1697_Closed_Text.style.display='none'; Codehighlighter1_1050_1697_Open_Image.style.display='inline'; Codehighlighter1_1050_1697_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">(</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"> pages; j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)</span><span id="Codehighlighter1_1050_1697_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_1050_1697_Open_Text"><span style="COLOR: #000000">{<br /><img id="Codehighlighter1_1103_1375_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1103_1375_Open_Text.style.display='none'; Codehighlighter1_1103_1375_Closed_Image.style.display='inline'; Codehighlighter1_1103_1375_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1103_1375_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1103_1375_Closed_Text.style.display='none'; Codehighlighter1_1103_1375_Open_Image.style.display='inline'; Codehighlighter1_1103_1375_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(sheets[j].front.left </span><span style="COLOR: #000000">||</span><span style="COLOR: #000000"> sheets[j].front.right)</span><span id="Codehighlighter1_1103_1375_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_1103_1375_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            cout </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Sheet </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> j</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, front: </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">if</span><span style="COLOR: #000000">(sheets[j].front.left)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                cout </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> sheets[j].front.left </span><span style="COLOR: #000000">&lt;&lt;</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" />            </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                cout </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Blank,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            cout </span><span style="COLOR: #000000">&lt;&lt;</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" />            </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(sheets[j].front.right)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                cout </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> sheets[j].front.right;<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" />                cout </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Blank,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            cout </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="COLOR: #000000"><br /><img id="Codehighlighter1_1426_1693_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1426_1693_Open_Text.style.display='none'; Codehighlighter1_1426_1693_Closed_Image.style.display='inline'; Codehighlighter1_1426_1693_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1426_1693_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1426_1693_Closed_Text.style.display='none'; Codehighlighter1_1426_1693_Open_Image.style.display='inline'; Codehighlighter1_1426_1693_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(sheets[j].back.left </span><span style="COLOR: #000000">||</span><span style="COLOR: #000000"> sheets[j].back.right)</span><span id="Codehighlighter1_1426_1693_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_1426_1693_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            cout </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Sheet </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> j</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, back : </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">if</span><span style="COLOR: #000000">(sheets[j].back.left)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                cout </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> sheets[j].back.left </span><span style="COLOR: #000000">&lt;&lt;</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" />            </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                cout </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Blank,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            cout </span><span style="COLOR: #000000">&lt;&lt;</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" />            </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(sheets[j].back.right)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                cout </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> sheets[j].back.right;<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" />                cout </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Blank</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            cout </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> endl;<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"><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" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> main()<br /><img id="Codehighlighter1_1714_1829_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1714_1829_Open_Text.style.display='none'; Codehighlighter1_1714_1829_Closed_Image.style.display='inline'; Codehighlighter1_1714_1829_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_1714_1829_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1714_1829_Closed_Text.style.display='none'; Codehighlighter1_1714_1829_Open_Image.style.display='inline'; Codehighlighter1_1714_1829_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_1714_1829_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_1714_1829_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"> numSides;<br /><img id="Codehighlighter1_1754_1816_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1754_1816_Open_Text.style.display='none'; Codehighlighter1_1754_1816_Closed_Image.style.display='inline'; Codehighlighter1_1754_1816_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1754_1816_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1754_1816_Closed_Text.style.display='none'; Codehighlighter1_1754_1816_Open_Image.style.display='inline'; Codehighlighter1_1754_1816_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(cin </span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000"> numSides)</span><span id="Codehighlighter1_1754_1816_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_1754_1816_Open_Text"><span style="COLOR: #000000">{<br /><img id="Codehighlighter1_1775_1789_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1775_1789_Open_Text.style.display='none'; Codehighlighter1_1775_1789_Closed_Image.style.display='inline'; Codehighlighter1_1775_1789_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1775_1789_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1775_1789_Closed_Text.style.display='none'; Codehighlighter1_1775_1789_Open_Image.style.display='inline'; Codehighlighter1_1775_1789_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(numSides </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)</span><span id="Codehighlighter1_1775_1789_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_1775_1789_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="COLOR: #0000ff">break</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" />        PrintPages(numSides);<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">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/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span></div></pre><img src ="http://www.cppblog.com/mahudu/aggbug/8652.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mahudu/" target="_blank">mahudu@cppblog</a> 2006-06-16 23:26 <a href="http://www.cppblog.com/mahudu/archive/2006/06/16/8652.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>The Blocks Problem</title><link>http://www.cppblog.com/mahudu/archive/2006/06/10/8364.html</link><dc:creator>mahudu@cppblog</dc:creator><author>mahudu@cppblog</author><pubDate>Fri, 09 Jun 2006 17:16:00 GMT</pubDate><guid>http://www.cppblog.com/mahudu/archive/2006/06/10/8364.html</guid><wfw:comment>http://www.cppblog.com/mahudu/comments/8364.html</wfw:comment><comments>http://www.cppblog.com/mahudu/archive/2006/06/10/8364.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/mahudu/comments/commentRss/8364.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mahudu/services/trackbacks/8364.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Background 		Many areas of Computer Science use simple, abstract domains for both analytical and empirical studies. For example, an early AI study of planning and robotics (STRIPS) used a block worl...&nbsp;&nbsp;<a href='http://www.cppblog.com/mahudu/archive/2006/06/10/8364.html'>阅读全文</a><img src ="http://www.cppblog.com/mahudu/aggbug/8364.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mahudu/" target="_blank">mahudu@cppblog</a> 2006-06-10 01:16 <a href="http://www.cppblog.com/mahudu/archive/2006/06/10/8364.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Fibonacci Freeze</title><link>http://www.cppblog.com/mahudu/archive/2006/06/10/8363.html</link><dc:creator>mahudu@cppblog</dc:creator><author>mahudu@cppblog</author><pubDate>Fri, 09 Jun 2006 17:10:00 GMT</pubDate><guid>http://www.cppblog.com/mahudu/archive/2006/06/10/8363.html</guid><wfw:comment>http://www.cppblog.com/mahudu/comments/8363.html</wfw:comment><comments>http://www.cppblog.com/mahudu/archive/2006/06/10/8363.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mahudu/comments/commentRss/8363.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mahudu/services/trackbacks/8363.html</trackback:ping><description><![CDATA[
		<p>The Fibonacci numbers (0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ...) are defined by the recurrence: </p>
		<p>
				<img height="68" alt="eqnarray20" src="http://acm.uva.es/p/v4/495img1.gif" width="500" align="bottom" />
		</p>
		<p>
		</p>
		<p>Write a program to calculate the Fibonacci Numbers. </p>
		<p>
		</p>
		<h2>
				<font color="#0070e8">
						<a name="SECTION0001001000000000000000">Input and Output</a>
				</font>
		</h2>
		<p>The input to your program would be a sequence of numbers smaller or equal than 5000, each on a separate line, specifying which Fibonacci number to calculate. </p>
		<p>
		</p>
		<p>Your program should output the Fibonacci number for each input value, one per line. </p>
		<p>
		</p>
		<h2>
				<font color="#0070e8">
						<a name="SECTION0001002000000000000000">Sample Input</a>
				</font>
		</h2>
		<p>
		</p>
		<pre>5<br />7<br />11</pre>
		<p>
		</p>
		<h2>
				<font color="#0070e8">
						<a name="SECTION0001003000000000000000">Sample Output</a>
				</font>
		</h2>
		<p>
		</p>
		<pre>The Fibonacci number for 5 is 5<br />The Fibonacci number for 7 is 13<br />The Fibonacci number for 11 is 89</pre>
		<br />
		<h2>
				<font size="+0">
						<font color="#0070e8">
								<a name="SECTION0001003000000000000000">Solution</a>
						</font>
				</font>
		</h2>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">#include</span>
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="COLOR: maroon">&lt;iostream&gt;<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /?><o:p></o:p></span>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">using</span>
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="COLOR: blue">namespace</span>
						<span style="COLOR: black">std</span>;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<o:p> </o:p>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">int</span>
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="COLOR: black">main</span>()<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">{<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 1">   </span>
						<span style="COLOR: blue">int</span>
						<span style="COLOR: black">first</span>,<span style="COLOR: black">next</span>,<span style="COLOR: black">temp</span>,<span style="COLOR: black">n</span>;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 1">   </span>
						<span style="COLOR: blue">while</span>(<span style="COLOR: black">cin</span> &gt;&gt; <span style="COLOR: black">n</span>) { <o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 2">      </span>
						<span style="COLOR: black">first</span> = 0;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 2">      </span>
						<span style="COLOR: black">next</span> = 1;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 2">      </span>
						<span style="COLOR: black">temp</span> = 0;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 2">      </span>
						<span style="COLOR: blue">if</span>(<span style="COLOR: black">n</span> == 0 || <span style="COLOR: black">n</span> == 1) {<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 3">        </span>
						<span style="COLOR: black">cout</span> &lt;&lt; <span style="COLOR: maroon">"The Fibonacci number for"</span> &lt;&lt; <span style="COLOR: maroon">" "</span> &lt;&lt; <span style="COLOR: black">n</span> &lt;&lt; <span style="COLOR: maroon">" "</span> &lt;&lt; <span style="COLOR: maroon">"is"</span> &lt;&lt; <span style="COLOR: maroon">" "</span> &lt;&lt; <span style="COLOR: black">n</span> &lt;&lt; <span style="COLOR: black">endl</span>;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 2">      </span>}<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 2">      </span>
						<span style="COLOR: blue">else</span> {<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 3">        </span>
						<span style="COLOR: blue">for</span>(<span style="COLOR: blue">int</span><span style="COLOR: black">i</span> = 2; <span style="COLOR: black">i</span> &lt;= <span style="COLOR: black">n</span>; <span style="COLOR: black">i</span>++) {<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 4">           </span>
						<span style="COLOR: black">temp</span> = <span style="COLOR: black">first</span> + <span style="COLOR: black">next</span>;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 4">           </span>
						<span style="COLOR: black">first</span> = <span style="COLOR: black">next</span>;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 4">           </span>
						<span style="COLOR: black">next</span> = <span style="COLOR: black">temp</span>;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 3">        </span>}<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 3">        </span>
						<span style="COLOR: black">cout</span> &lt;&lt; <span style="COLOR: maroon">"The Fibonacci number for"</span> &lt;&lt; <span style="COLOR: maroon">" "</span> &lt;&lt; <span style="COLOR: black">n</span> &lt;&lt; <span style="COLOR: maroon">" "</span> &lt;&lt; <span style="COLOR: maroon">"is"</span> &lt;&lt; <span style="COLOR: maroon">" "</span> &lt;&lt; <span style="COLOR: black">temp</span> &lt;&lt; <span style="COLOR: black">endl</span>;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 2">      </span>}<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 1">   </span>}<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 1">   </span>
						<span style="COLOR: blue">return</span> 0;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">}</span>
		</p>
<img src ="http://www.cppblog.com/mahudu/aggbug/8363.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mahudu/" target="_blank">mahudu@cppblog</a> 2006-06-10 01:10 <a href="http://www.cppblog.com/mahudu/archive/2006/06/10/8363.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>The 3n + 1 problem</title><link>http://www.cppblog.com/mahudu/archive/2006/06/10/8362.html</link><dc:creator>mahudu@cppblog</dc:creator><author>mahudu@cppblog</author><pubDate>Fri, 09 Jun 2006 16:41:00 GMT</pubDate><guid>http://www.cppblog.com/mahudu/archive/2006/06/10/8362.html</guid><wfw:comment>http://www.cppblog.com/mahudu/comments/8362.html</wfw:comment><comments>http://www.cppblog.com/mahudu/archive/2006/06/10/8362.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/mahudu/comments/commentRss/8362.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mahudu/services/trackbacks/8362.html</trackback:ping><description><![CDATA[
		<h2>
				<font color="#0000ff">
						<a name="SECTION0001001000000000000000">
						</a>
				</font>
		</h2>
		<h2>
				<font size="+0">
						<font color="#0070e8">
								<a name="SECTION0001001000000000000000">Background</a>
						</font>
				</font>
		</h2>
		<h2>
				<a name="SECTION0001001000000000000000">
				</a>
				<font color="#0000ff">
						<a name="SECTION0001001000000000000000">
						</a>
				</font>
		</h2>
		<h2>
				<font color="#0070e8">
				</font>
		</h2>
		<p>Problems in Computer Science are often classified as belonging to a certain class of problems (e.g., NP, Unsolvable, Recursive). In this problem you will be analyzing a property of an algorithm whose classification is not known for all possible inputs. </p>
		<p>
		</p>
		<h2>
				<font color="#0070e8">
						<a name="SECTION0001002000000000000000">The Problem</a>
				</font>
		</h2>
		<p>Consider the following algorithm: </p>
		<pre>1.	input n<font color="#000000"><br /><br />2. 	print n<br /><br />3. 	if n = 1 then STOP<br /><br />4. 	if n is odd then  tex2html_wrap_inline44<br /><br />5. 	else  tex2html_wrap_inline46<br /><br />6. 	GOTO 2</font></pre>
		<p>Given the input 22, the following sequence of numbers will be printed 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 </p>
		<p>It is conjectured that the algorithm above will terminate (when a 1 is printed) for any integral input value. Despite the simplicity of the algorithm, it is unknown whether this conjecture is true. It has been verified, however, for all integers <i>n</i> such that 0 &lt; <i>n</i> &lt; 1,000,000 (and, in fact, for many more numbers than this.) </p>
		<p>Given an input <i>n</i>, it is possible to determine the number of numbers printed (including the 1). For a given <i>n</i> this is called the <em>cycle-length</em> of <i>n</i>. In the example above, the cycle length of 22 is 16. </p>
		<p>For any two numbers <i>i</i> and <i>j</i> you are to determine the maximum cycle length over all numbers between <u><i>i</i> and <i>j</i>. </u></p>
		<p>
		</p>
		<h2>
				<font color="#0070e8">
						<a name="SECTION0001003000000000000000">The Input</a>
				</font>
		</h2>
		<p>The input will consist of a series of pairs of integers <i>i</i> and <i>j</i>, one pair of integers per line. All integers will be less than 1,000,000 and greater than 0. </p>
		<p>You should process all pairs of integers and for each pair determine the maximum cycle length over all integers between and including <i>i</i> and <i>j</i>. </p>
		<p>You can assume that no opperation overflows a 32-bit integer. </p>
		<p>
		</p>
		<h2>
				<font color="#0070e8">
						<a name="SECTION0001004000000000000000">The Output</a>
				</font>
		</h2>
		<p>For each pair of input integers <i>i</i> and <i>j</i> you should output <i>i</i>, <i>j</i>, and the maximum cycle length for integers between and including <i>i</i> and <i>j</i>. These three numbers should be separated by at least one space with all three numbers on one line and with one line of output for each line of input. The integers <i>i</i> and <i>j</i> must appear in the output in the same order in which they appeared in the input and should be followed by the maximum cycle length (on the same line). </p>
		<p>
		</p>
		<h2>
				<font color="#0070e8">
						<a name="SECTION0001005000000000000000">Sample Input</a>
				</font>
		</h2>
		<p>
		</p>
		<pre>1 10<br />100 200<br />201 210<br />900 1000<br /></pre>
		<p>
		</p>
		<h2>
				<font color="#0070e8">
						<a name="SECTION0001006000000000000000">Sample Output</a>
				</font>
		</h2>
		<p>
		</p>
		<pre>1 10 20<br />100 200 125<br />201 210 89<br />900 1000 174<br /></pre>
		<br />
		<h2>
				<font size="+0">
						<font color="#0070e8">
								<a name="SECTION0001006000000000000000">Solution</a>
						</font>
				</font>   <br /></h2>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">#include</span>
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="COLOR: maroon">&lt;iostream&gt;<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /?><o:p></o:p></span>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">using</span>
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="COLOR: blue">namespace</span>
						<span style="COLOR: black">std</span>;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<o:p> </o:p>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">int</span>
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="COLOR: black">cycle</span>(<span style="COLOR: blue">int</span><span style="COLOR: black">m</span>)<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">{<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 1">   </span>
						<span style="COLOR: blue">int</span>
						<span style="COLOR: black">i</span> = 1;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 1">   </span>
						<span style="COLOR: blue">while</span> (<span style="COLOR: black">m</span> != 1){<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 2">      </span>
						<span style="COLOR: blue">if</span>(<span style="COLOR: black">m</span>%2)<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 3">        </span>
						<span style="COLOR: black">m</span> = <span style="COLOR: black">m</span>*3 + 1;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 2">      </span>
						<span style="COLOR: blue">else<o:p></o:p></span>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 3">        </span>
						<span style="COLOR: black">m</span> /= 2;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 2">      </span>
						<span style="COLOR: black">i</span>++;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 1">   </span>}<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 1">   </span>
						<span style="COLOR: blue">return</span>
						<span style="COLOR: black">i</span>;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">}<span style="mso-spacerun: yes">   </span><o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<o:p> </o:p>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">int</span>
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="COLOR: black">main</span>()<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">{<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 1">   </span>
						<span style="COLOR: blue">int</span>
						<span style="COLOR: black">m</span>,<span style="COLOR: black">n</span>,<span style="COLOR: black">max</span>,<span style="COLOR: black">temp</span>;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 1">   </span>
						<span style="COLOR: blue">int</span>
						<span style="COLOR: black">mOriginal</span>,<span style="COLOR: black">nOriginal</span>;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 1">   </span>
						<span style="COLOR: blue">int</span>
						<span style="COLOR: black">i</span>;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<o:p> </o:p>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 1">   </span>
						<span style="COLOR: blue">while</span> (<span style="COLOR: black">cin</span> &gt;&gt; <span style="COLOR: black">m</span> &gt;&gt; <span style="COLOR: black">n</span>){<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 2">      </span>
						<span style="COLOR: black">mOriginal</span> = <span style="COLOR: black">m</span>;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 2">      </span>
						<span style="COLOR: black">nOriginal</span> = <span style="COLOR: black">n</span>;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 2">      </span>
						<span style="COLOR: blue">if</span> (<span style="COLOR: black">m</span> &gt; <span style="COLOR: black">n</span>){<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 3">        </span>
						<span style="COLOR: black">temp</span> = <span style="COLOR: black">m</span>;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 3">        </span>
						<span style="COLOR: black">m</span> = <span style="COLOR: black">n</span>;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 3">        </span>
						<span style="COLOR: black">n</span> = <span style="COLOR: black">temp</span>;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 2">      </span>}<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<o:p> </o:p>
				</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 2">      </span>
						<span style="COLOR: black">max</span> = <span style="COLOR: black">cycle</span>(<span style="COLOR: black">m</span>);<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 2">      </span>
						<span style="COLOR: blue">for</span> (<span style="COLOR: black">i</span> = <span style="COLOR: black">m</span>+1; <span style="COLOR: black">i</span> &lt;= <span style="COLOR: black">n</span>; <span style="COLOR: black">i</span>++){<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 3">        </span>
						<span style="COLOR: black">temp</span> = <span style="COLOR: black">cycle</span>(<span style="COLOR: black">i</span>);<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 3">        </span>
						<span style="COLOR: blue">if</span> (<span style="COLOR: black">temp</span> &gt; <span style="COLOR: black">max</span>){<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 4">           </span>
						<span style="COLOR: black">max</span> = <span style="COLOR: black">temp</span>;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 3">        </span>}<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 2">      </span>}<span style="mso-spacerun: yes">  </span><o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 2">      </span>
						<span style="COLOR: black">cout</span> &lt;&lt; <span style="COLOR: black">mOriginal</span> &lt;&lt; <span style="COLOR: maroon">" "</span> &lt;&lt; <span style="COLOR: black">nOriginal</span> &lt;&lt; <span style="COLOR: maroon">" "</span> &lt;&lt; <span style="COLOR: black">max</span> &lt;&lt; <span style="COLOR: black">endl</span>;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 1">   </span>}<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">
						<span style="mso-tab-count: 1">   </span>
						<span style="COLOR: blue">return</span> 0;<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 13pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">}</span>
		</p>
<img src ="http://www.cppblog.com/mahudu/aggbug/8362.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mahudu/" target="_blank">mahudu@cppblog</a> 2006-06-10 00:41 <a href="http://www.cppblog.com/mahudu/archive/2006/06/10/8362.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>A + B Problem</title><link>http://www.cppblog.com/mahudu/archive/2006/06/10/8361.html</link><dc:creator>mahudu@cppblog</dc:creator><author>mahudu@cppblog</author><pubDate>Fri, 09 Jun 2006 16:32:00 GMT</pubDate><guid>http://www.cppblog.com/mahudu/archive/2006/06/10/8361.html</guid><wfw:comment>http://www.cppblog.com/mahudu/comments/8361.html</wfw:comment><comments>http://www.cppblog.com/mahudu/archive/2006/06/10/8361.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mahudu/comments/commentRss/8361.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mahudu/services/trackbacks/8361.html</trackback:ping><description><![CDATA[
		<p>Calculate a + b </p>
		<h2 style="color: rgb(26, 92, 200);">Input</h2>
		<p>a and b</p>
		<h2 style="color: rgb(26, 92, 200);">Output</h2>
		<p>a+b</p>
		<h2 style="color: rgb(26, 92, 200);">Sample Input</h2>
		<pre>1 5</pre>
		<h2 style="color: rgb(26, 92, 200);">Sample Output</h2>
		<pre>6<br /><br /></pre>
		<h2 style="color: rgb(26, 92, 200);">Solution</h2>
		#include &lt;iostream&gt;<br />using namespace std;<br /><br />int main()<br />{<br />     int a,b;<br />    while(cin &gt;&gt; a &gt;&gt; b);<br />         cout &lt;&lt; a+b &lt;&lt; endl;<br />     return 0;<br />}<br /><img src ="http://www.cppblog.com/mahudu/aggbug/8361.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mahudu/" target="_blank">mahudu@cppblog</a> 2006-06-10 00:32 <a href="http://www.cppblog.com/mahudu/archive/2006/06/10/8361.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>