﻿<?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++博客-hjl-cqu</title><link>http://www.cppblog.com/hjl-cqu/</link><description>cqu</description><language>zh-cn</language><lastBuildDate>Sun, 05 Apr 2026 18:11:16 GMT</lastBuildDate><pubDate>Sun, 05 Apr 2026 18:11:16 GMT</pubDate><ttl>60</ttl><item><title>参加第三届华为杯程序设计大赛遇到的一个小问题，求解示</title><link>http://www.cppblog.com/hjl-cqu/archive/2011/05/28/147471.html</link><dc:creator>hjl</dc:creator><author>hjl</author><pubDate>Sat, 28 May 2011 05:11:00 GMT</pubDate><guid>http://www.cppblog.com/hjl-cqu/archive/2011/05/28/147471.html</guid><wfw:comment>http://www.cppblog.com/hjl-cqu/comments/147471.html</wfw:comment><comments>http://www.cppblog.com/hjl-cqu/archive/2011/05/28/147471.html#Feedback</comments><slash:comments>8</slash:comments><wfw:commentRss>http://www.cppblog.com/hjl-cqu/comments/commentRss/147471.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/hjl-cqu/services/trackbacks/147471.html</trackback:ping><description><![CDATA[其中题目如下：<br />&nbsp; 给定一个整数，求出比其大的最小的不重复数字，不重复数字小于100000，不重复数字定义如下：<br /><br />&nbsp;&nbsp; 任意两个相邻位上的数字均不相等。例如：1212,323,65是不重复数字，122,100,1123为重复数字。<br /><br />实例：<br />&nbsp; 输入：99<br />&nbsp; 输出：101<br />&nbsp; <br />&nbsp; 输入：65<br />&nbsp; 输出：67<br /><br />我编的程序如下： 
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><span style="color: #000000">#include&nbsp;</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"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_54_601_Open_Image" onclick="this.style.display='none'; Codehighlighter1_54_601_Open_Text.style.display='none'; Codehighlighter1_54_601_Closed_Image.style.display='inline'; Codehighlighter1_54_601_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_54_601_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_54_601_Closed_Text.style.display='none'; Codehighlighter1_54_601_Open_Image.style.display='inline'; Codehighlighter1_54_601_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_54_601_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"  alt="" /></span><span id="Codehighlighter1_54_601_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;start</span><span style="color: #000000">=</span><span style="color: #000000">99</span><span style="color: #000000">;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">给出的数据，求其不重复数</span><span style="color: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;sgnl</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;shu</span><span style="color: #000000">=-</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;T;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;p;&nbsp;&nbsp;&nbsp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /><img id="Codehighlighter1_148_166_Open_Image" onclick="this.style.display='none'; Codehighlighter1_148_166_Open_Text.style.display='none'; Codehighlighter1_148_166_Closed_Image.style.display='inline'; Codehighlighter1_148_166_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_148_166_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_148_166_Closed_Text.style.display='none'; Codehighlighter1_148_166_Open_Image.style.display='inline'; Codehighlighter1_148_166_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a[]</span><span style="color: #000000">=</span><span id="Codehighlighter1_148_166_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"  alt="" /></span><span id="Codehighlighter1_148_166_Open_Text"><span style="color: #000000">{</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">,</span><span style="color: #000000">-</span><span style="color: #000000">2</span><span style="color: #000000">,</span><span style="color: #000000">-</span><span style="color: #000000">3</span><span style="color: #000000">,</span><span style="color: #000000">-</span><span style="color: #000000">4</span><span style="color: #000000">,</span><span style="color: #000000">-</span><span style="color: #000000">5</span><span style="color: #000000">,</span><span style="color: #000000">-</span><span style="color: #000000">6</span><span style="color: #000000">}</span></span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">start;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">100000</span><span style="color: #000000">;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img id="Codehighlighter1_204_538_Open_Image" onclick="this.style.display='none'; Codehighlighter1_204_538_Open_Text.style.display='none'; Codehighlighter1_204_538_Closed_Image.style.display='inline'; Codehighlighter1_204_538_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_204_538_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_204_538_Closed_Text.style.display='none'; Codehighlighter1_204_538_Open_Image.style.display='inline'; Codehighlighter1_204_538_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;</span><span id="Codehighlighter1_204_538_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"  alt="" /></span><span id="Codehighlighter1_204_538_Open_Text"><span style="color: #000000">{&nbsp;&nbsp;&nbsp;&nbsp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;&nbsp;sgnl=-1;</span><span style="color: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T</span><span style="color: #000000">=</span><span style="color: #000000">i;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">&nbsp;(T</span><span style="color: #000000">!=</span><span style="color: #000000">0</span><span style="color: #000000">)<br /><img id="Codehighlighter1_259_471_Open_Image" onclick="this.style.display='none'; Codehighlighter1_259_471_Open_Text.style.display='none'; Codehighlighter1_259_471_Closed_Image.style.display='inline'; Codehighlighter1_259_471_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_259_471_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_259_471_Closed_Text.style.display='none'; Codehighlighter1_259_471_Open_Image.style.display='inline'; Codehighlighter1_259_471_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_259_471_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_259_471_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[p]</span><span style="color: #000000">=</span><span style="color: #000000">T</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"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T</span><span style="color: #000000">=</span><span style="color: #000000">T</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"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(p</span><span style="color: #000000">&gt;</span><span style="color: #000000">0</span><span style="color: #000000">)<br /><img id="Codehighlighter1_305_375_Open_Image" onclick="this.style.display='none'; Codehighlighter1_305_375_Open_Text.style.display='none'; Codehighlighter1_305_375_Closed_Image.style.display='inline'; Codehighlighter1_305_375_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_305_375_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_305_375_Closed_Text.style.display='none'; Codehighlighter1_305_375_Open_Image.style.display='inline'; Codehighlighter1_305_375_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_305_375_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"  alt="" /></span><span id="Codehighlighter1_305_375_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(a[p</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">]</span><span style="color: #000000">==</span><span style="color: #000000">a[p])<br /><img id="Codehighlighter1_335_369_Open_Image" onclick="this.style.display='none'; Codehighlighter1_335_369_Open_Text.style.display='none'; Codehighlighter1_335_369_Closed_Image.style.display='inline'; Codehighlighter1_335_369_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_335_369_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_335_369_Closed_Text.style.display='none'; Codehighlighter1_335_369_Open_Image.style.display='inline'; Codehighlighter1_335_369_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_335_369_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"  alt="" /></span><span id="Codehighlighter1_335_369_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sgnl</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;&nbsp;if&nbsp;(p&gt;0)</span><span style="color: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(T</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(sgnl</span><span style="color: #000000">!=</span><span style="color: #000000">0</span><span style="color: #000000">)<br /><img id="Codehighlighter1_424_457_Open_Image" onclick="this.style.display='none'; Codehighlighter1_424_457_Open_Text.style.display='none'; Codehighlighter1_424_457_Closed_Image.style.display='inline'; Codehighlighter1_424_457_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_424_457_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_424_457_Closed_Text.style.display='none'; Codehighlighter1_424_457_Open_Image.style.display='inline'; Codehighlighter1_424_457_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_424_457_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_424_457_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;shu</span><span style="color: #000000">=</span><span style="color: #000000">i;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">100000</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000">++</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #008000">//</span><span style="color: #008000">while&nbsp;(T!=0)</span><span style="color: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;y</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;y</span><span style="color: #000000">&lt;</span><span style="color: #000000">6</span><span style="color: #000000">;y</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img id="Codehighlighter1_515_534_Open_Image" onclick="this.style.display='none'; Codehighlighter1_515_534_Open_Text.style.display='none'; Codehighlighter1_515_534_Closed_Image.style.display='inline'; Codehighlighter1_515_534_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_515_534_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_515_534_Closed_Text.style.display='none'; Codehighlighter1_515_534_Open_Image.style.display='inline'; Codehighlighter1_515_534_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_515_534_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"  alt="" /></span><span id="Codehighlighter1_515_534_Open_Text"><span style="color: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[y]</span><span style="color: #000000">=</span><span style="color: #000000">0</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"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;}</span></span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;&nbsp;for&nbsp;(int&nbsp;i=50;i&lt;60;i++)</span><span style="color: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">shu</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;&nbsp;&nbsp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span></div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 开始的时候我认为上述代码是没有任何问题的，但是当每次运行程序的时候都得不到正确的结果。经过多次的调试，我发现在上述While循环中为sgnl赋值以后，到下面的判断处是，sgnl的值貌似不存在一样。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 然后我对程序做了一点修改，仅仅在for循环的里边加了一条语句：sgnl=-1;也就是上述代码注销的地方，然后再次运行程序，结果无误。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 虽然发现了问题，可是我并处清楚这是问什么，所以贴出来希望各位大虾能够帮忙解答一下。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;小弟不胜感激。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 期待中。<br /><img src ="http://www.cppblog.com/hjl-cqu/aggbug/147471.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/hjl-cqu/" target="_blank">hjl</a> 2011-05-28 13:11 <a href="http://www.cppblog.com/hjl-cqu/archive/2011/05/28/147471.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>大整数划分问题</title><link>http://www.cppblog.com/hjl-cqu/archive/2010/04/12/112388.html</link><dc:creator>hjl</dc:creator><author>hjl</author><pubDate>Mon, 12 Apr 2010 14:55:00 GMT</pubDate><guid>http://www.cppblog.com/hjl-cqu/archive/2010/04/12/112388.html</guid><wfw:comment>http://www.cppblog.com/hjl-cqu/comments/112388.html</wfw:comment><comments>http://www.cppblog.com/hjl-cqu/archive/2010/04/12/112388.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/hjl-cqu/comments/commentRss/112388.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/hjl-cqu/services/trackbacks/112388.html</trackback:ping><description><![CDATA[<p>本程序采用简单的递归调用来实现对大数的划分。<br>程序源代码：<br>#include&lt;iostream&gt;<br>using namespace std;<br>void main()<br>{<br>&nbsp;int q(int n,int m);<br>&nbsp;int a;<br>&nbsp;&nbsp;&nbsp; cout&lt;&lt;"请输入你要划分的整数："&lt;&lt;endl;<br>&nbsp;cin&gt;&gt;a;<br>&nbsp;cout&lt;&lt;q(a,a)&lt;&lt;endl;<br>}<br>//以下代码为程序的关键部分&nbsp;&nbsp; 计划分大整数的算法</p>
<p style="FONT-SIZE: 18pt">int q(int n,int m)<br>{<br>&nbsp;&nbsp; if(n&lt;1||m&lt;1)<br>&nbsp;&nbsp;&nbsp; return 0;<br>&nbsp;&nbsp; if(n==1||m==1)<br>&nbsp;&nbsp;&nbsp; return 1;<br>&nbsp;&nbsp; if(n&lt;m)<br>&nbsp;&nbsp;&nbsp; return q(n,n);<br>&nbsp;&nbsp; if(n==m)<br>&nbsp;&nbsp;&nbsp; return (q(n,m-1)+1);<br>&nbsp;&nbsp; return q(n,m-1)+q(n-m,m);<br>}</p>
<img src ="http://www.cppblog.com/hjl-cqu/aggbug/112388.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/hjl-cqu/" target="_blank">hjl</a> 2010-04-12 22:55 <a href="http://www.cppblog.com/hjl-cqu/archive/2010/04/12/112388.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>