📄 字符串全排列(迅雷笔试题) - sinall的专栏 - csdnblog.htm
字号:
<LI><A href="http://blog.csdn.net/sinall/archive/2006/09.aspx">2006年09月(2)</A>
<LI><A href="http://blog.csdn.net/sinall/archive/2006/08.aspx">2006年08月(3)</A>
<LI><A href="http://blog.csdn.net/sinall/archive/2006/07.aspx">2006年07月(3)</A>
<LI><A href="http://blog.csdn.net/sinall/archive/2006/06.aspx">2006年06月(1)</A>
<LI><A href="http://blog.csdn.net/sinall/archive/2006/04.aspx">2006年04月(2)</A>
<LI><A href="http://blog.csdn.net/sinall/archive/2006/03.aspx">2006年03月(1)</A>
<LI><A href="http://blog.csdn.net/sinall/archive/2006/01.aspx">2006年01月(1)</A>
<LI><A href="http://blog.csdn.net/sinall/archive/2005/12.aspx">2005年12月(2)</A>
<LI><A href="http://blog.csdn.net/sinall/archive/2005/11.aspx">2005年11月(4)</A>
<LI><A href="http://blog.csdn.net/sinall/archive/2005/10.aspx">2005年10月(1)</A>
<LI><A href="http://blog.csdn.net/sinall/archive/2005/09.aspx">2005年09月(1)</A>
<LI><A href="http://blog.csdn.net/sinall/archive/2005/08.aspx">2005年08月(3)</A>
<LI><A href="http://blog.csdn.net/sinall/archive/2005/07.aspx">2005年07月(1)</A>
<LI><A href="http://blog.csdn.net/sinall/archive/2005/06.aspx">2005年06月(1)</A>
<LI><A href="http://blog.csdn.net/sinall/archive/2005/05.aspx">2005年05月(4)</A>
<LI><A
href="http://blog.csdn.net/sinall/archive/2005/04.aspx">2005年04月(2)</A></LI></UL><SPAN
id=Anthem_RecentComments_ltlComments__><SPAN id=RecentComments_ltlComments>
<H3 class=listtitle>最近评论</H3>
<UL class=list>
<LI class=listitem>sinall:<A title=点击查看《回复:为什么C++不允许析构函数抛出异常?》
href="http://blog.csdn.net/sinall/archive/2007/04/06/1553697.aspx#733432">根本原因就是:try块中如果有异常的话,局部对象会析构。</A>
<LI class=listitem>sinall:<A title=点击查看《回复:为什么C++不允许析构函数抛出异常?》
href="http://blog.csdn.net/sinall/archive/2007/04/06/1553697.aspx#733430">:-),我没说明白。<BR>catch
(Foo e)<BR>...{<BR>// 继续运行这块代码?因为抛出的异常是Foo类型的,所以应该执行这段代码。<BR>}<BR>catch (Bar
e)<BR>...{<BR>// 还是继续运行这块代码,难以决断!因为抛出异常的地方,try块局部变……</A>
<LI class=listitem>zhcen:<A title=点击查看《回复:在ActiveX控件中引入窗体技术(转载)》
href="http://blog.csdn.net/sinall/archive/2005/05/23/379021.aspx#733099">把你添加的成员变量
用 动态方式创建 就没什么问题了<BR><BR>比如<BR><BR>CHelloDialog* m_pDlgHello;<BR><BR></A>
<LI class=listitem>jiapei100:<A title=点击查看《回复:为什么C++不允许析构函数抛出异常?》
href="http://blog.csdn.net/sinall/archive/2007/04/06/1553697.aspx#731273"><BR>兄弟,这个问题,能不能解释得更清晰一些?多谢了!!<BR><BR>catch
(Foo e)<BR>...{<BR>// 继续运行这块代码?<BR>}<BR>catch (Bar e)<BR>...{<BR>//
还是继续运行这块代码,难以决断!<BR>}<BR><……</A>
<LI class=listitem>thunder_silent:<A title=点击查看《回复:在ActiveX控件中引入窗体技术(转载)》
href="http://blog.csdn.net/sinall/archive/2005/05/23/379021.aspx#730510">太感谢搂主了!</A></LI></UL></SPAN></SPAN><BR><BR></DIV>
<DIV id=main><SPAN class=PreAndNext id=viewpost.ascx_PreviousAndNextEntriesUp>
<DIV align=center><A
href="http://blog.csdn.net/sinall/archive/2006/12/22/1452614.aspx">上一篇: OTL
操作 Oracle BLOB 时“ORA-22990: LOB 定位器无法扩展事务处理”的解决方法</A> | <A
href="http://blog.csdn.net/sinall/archive/2006/11/09/1375078.aspx">下一篇: C++
简单类型转字符串的四种方法</A></DIV></SPAN><BR>
<SCRIPT>function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}</SCRIPT>
<DIV class=post>
<DIV class=postTitle>
<SCRIPT src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/vote.js"></SCRIPT>
<A href="http://blog.csdn.net/sinall/archive/2006/11/11/1379441.aspx"><IMG
height=13 src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/authorship.gif"
width=15 border=0> 字符串全排列(迅雷笔试题)</A>
<SCRIPT src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/count.htm"></SCRIPT>
</DIV>
<DIV class=postText>
<DIV style="TEXT-ALIGN: left">题目见:<BR></DIV><A
href="http://community.csdn.net/Expert/TopicView3.asp?id=5126306">http://community.csdn.net/Expert/TopicView3.asp?id=5126306</A><BR>用C++写一个函数,
如 Foo(const char *str), 打印出 str 的全排列, <BR>如 abc 的全排列: abc, acb, bca, dac, cab,
cba<BR>解答:<BR>呵呵,来给大伙说说原理:<BR>A(n,n) = n!<BR>=>A(n,n) =
A(n-1,n-1)*n<BR>有了递推公式,就可以写递归函数了:<BR><BR>
<DIV
style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: rgb(230,230,230) 0% 50%; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 95%; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
<DIV><IMG alt="" src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/None.gif"
align=top><SPAN style="COLOR: rgb(0,0,0)">#include </SPAN><SPAN
style="COLOR: rgb(0,0,0)"><</SPAN><SPAN
style="COLOR: rgb(0,0,0)">vector</SPAN><SPAN
style="COLOR: rgb(0,0,0)">></SPAN><SPAN style="COLOR: rgb(0,0,0)"><BR><IMG
alt="" src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/None.gif"
align=top>#include </SPAN><SPAN style="COLOR: rgb(0,0,0)"><</SPAN><SPAN
style="COLOR: rgb(0,0,255)">string</SPAN><SPAN
style="COLOR: rgb(0,0,0)">></SPAN><SPAN style="COLOR: rgb(0,0,0)"><BR><IMG
alt="" src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/None.gif"
align=top>#include </SPAN><SPAN style="COLOR: rgb(0,0,0)"><</SPAN><SPAN
style="COLOR: rgb(0,0,0)">iostream</SPAN><SPAN
style="COLOR: rgb(0,0,0)">></SPAN><SPAN style="COLOR: rgb(0,0,0)"><BR><IMG
alt="" src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/None.gif"
align=top>#include </SPAN><SPAN style="COLOR: rgb(0,0,0)"><</SPAN><SPAN
style="COLOR: rgb(0,0,0)">algorithm</SPAN><SPAN
style="COLOR: rgb(0,0,0)">></SPAN><SPAN style="COLOR: rgb(0,0,0)"><BR><IMG
alt="" src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/None.gif"
align=top>#include </SPAN><SPAN style="COLOR: rgb(0,0,0)"><</SPAN><SPAN
style="COLOR: rgb(0,0,0)">iterator</SPAN><SPAN
style="COLOR: rgb(0,0,0)">></SPAN><SPAN style="COLOR: rgb(0,0,0)"><BR><IMG
alt="" src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/None.gif"
align=top></SPAN><SPAN style="COLOR: rgb(0,0,255)">using</SPAN><SPAN
style="COLOR: rgb(0,0,0)"> </SPAN><SPAN
style="COLOR: rgb(0,0,255)">namespace</SPAN><SPAN
style="COLOR: rgb(0,0,0)"> std;<BR><IMG alt=""
src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/None.gif" align=top><BR><IMG
alt="" src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/None.gif"
align=top>typedef vector</SPAN><SPAN
style="COLOR: rgb(0,0,0)"><</SPAN><SPAN
style="COLOR: rgb(0,0,255)">string</SPAN><SPAN
style="COLOR: rgb(0,0,0)">></SPAN><SPAN
style="COLOR: rgb(0,0,0)"> Permutation;<BR><IMG alt=""
src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/None.gif"
align=top>typedef vector</SPAN><SPAN
style="COLOR: rgb(0,0,0)"><</SPAN><SPAN
style="COLOR: rgb(0,0,255)">string</SPAN><SPAN
style="COLOR: rgb(0,0,0)">></SPAN><SPAN
style="COLOR: rgb(0,0,0)">::iterator PmtIterator;<BR><IMG alt=""
src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/None.gif" align=top><BR><IMG
alt="" src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/None.gif"
align=top></SPAN><SPAN style="COLOR: rgb(0,128,0)">//</SPAN><SPAN
style="COLOR: rgb(0,128,0)"> 计算templet字符串中从pos位置开始的全排列</SPAN><SPAN
style="COLOR: rgb(0,128,0)"><BR><IMG alt=""
src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/None.gif" align=top></SPAN><SPAN
style="COLOR: rgb(0,0,0)">Permutation permute(</SPAN><SPAN
style="COLOR: rgb(0,0,255)">const</SPAN><SPAN
style="COLOR: rgb(0,0,0)"> </SPAN><SPAN
style="COLOR: rgb(0,0,255)">string</SPAN><SPAN
style="COLOR: rgb(0,0,0)">&</SPAN><SPAN
style="COLOR: rgb(0,0,0)"> templet, </SPAN><SPAN
style="COLOR: rgb(0,0,255)">string</SPAN><SPAN
style="COLOR: rgb(0,0,0)">::size_type pos)<BR><IMG id=_297_767_Open_Image
onclick="this.style.display='none'; document.getElementById('_297_767_Open_Text').style.display='none'; document.getElementById('_297_767_Closed_Image').style.display='inline'; document.getElementById('_297_767_Closed_Text').style.display='inline';"
alt="" src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/ExpandedBlockStart.gif"
align=top><IMG id=_297_767_Closed_Image style="DISPLAY: none"
onclick="this.style.display='none'; document.getElementById('_297_767_Closed_Text').style.display='none'; document.getElementById('_297_767_Open_Image').style.display='inline'; document.getElementById('_297_767_Open_Text').style.display='inline';"
alt="" src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/ContractedBlock.gif"
align=top></SPAN><SPAN id=_297_767_Closed_Text
style="BORDER-RIGHT: rgb(128,128,128) 1px solid; BORDER-TOP: rgb(128,128,128) 1px solid; DISPLAY: none; BORDER-LEFT: rgb(128,128,128) 1px solid; BORDER-BOTTOM: rgb(128,128,128) 1px solid; BACKGROUND-COLOR: rgb(255,255,255)">...</SPAN><SPAN
id=_297_767_Open_Text><SPAN style="COLOR: rgb(0,0,0)">{<BR><IMG alt=""
src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/InBlock.gif"
align=top> Permutation temp;<BR><IMG alt=""
src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/InBlock.gif"
align=top> </SPAN><SPAN
style="COLOR: rgb(0,0,255)">if</SPAN><SPAN
style="COLOR: rgb(0,0,0)"> (pos </SPAN><SPAN
style="COLOR: rgb(0,0,0)">==</SPAN><SPAN
style="COLOR: rgb(0,0,0)"> templet.size()</SPAN><SPAN
style="COLOR: rgb(0,0,0)">-</SPAN><SPAN style="COLOR: rgb(0,0,0)">1</SPAN><SPAN
style="COLOR: rgb(0,0,0)">)<BR><IMG id=_349_408_Open_Image
onclick="this.style.display='none'; document.getElementById('_349_408_Open_Text').style.display='none'; document.getElementById('_349_408_Closed_Image').style.display='inline'; document.getElementById('_349_408_Closed_Text').style.display='inline';"
alt=""
src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/ExpandedSubBlockStart.gif"
align=top><IMG id=_349_408_Closed_Image style="DISPLAY: none"
onclick="this.style.display='none'; document.getElementById('_349_408_Closed_Text').style.display='none'; document.getElementById('_349_408_Open_Image').style.display='inline'; document.getElementById('_349_408_Open_Text').style.display='inline';"
alt="" src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/ContractedSubBlock.gif"
align=top> </SPAN><SPAN id=_349_408_Closed_Text
style="BORDER-RIGHT: rgb(128,128,128) 1px solid; BORDER-TOP: rgb(128,128,128) 1px solid; DISPLAY: none; BORDER-LEFT: rgb(128,128,128) 1px solid; BORDER-BOTTOM: rgb(128,128,128) 1px solid; BACKGROUND-COLOR: rgb(255,255,255)">...</SPAN><SPAN
id=_349_408_Open_Text><SPAN style="COLOR: rgb(0,0,0)">{<BR><IMG alt=""
src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/InBlock.gif"
align=top> temp.push_back(</SPAN><SPAN
style="COLOR: rgb(0,0,255)">string</SPAN><SPAN
style="COLOR: rgb(0,0,0)">(</SPAN><SPAN style="COLOR: rgb(0,0,0)">1</SPAN><SPAN
style="COLOR: rgb(0,0,0)">, templet[templet.size()</SPAN><SPAN
style="COLOR: rgb(0,0,0)">-</SPAN><SPAN style="COLOR: rgb(0,0,0)">1</SPAN><SPAN
style="COLOR: rgb(0,0,0)">]));<BR><IMG alt=""
src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/ExpandedSubBlockEnd.gif"
align=top> }</SPAN></SPAN><SPAN
style="COLOR: rgb(0,0,0)"><BR><IMG alt=""
src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/InBlock.gif"
align=top> </SPAN><SPAN
style="COLOR: rgb(0,0,255)">else</SPAN><SPAN style="COLOR: rgb(0,0,0)"><BR><IMG
id=_417_751_Open_Image
onclick="this.style.display='none'; document.getElementById('_417_751_Open_Text').style.display='none'; document.getElementById('_417_751_Closed_Image').style.display='inline'; document.getElementById('_417_751_Closed_Text').style.display='inline';"
alt=""
src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/ExpandedSubBlockStart.gif"
align=top><IMG id=_417_751_Closed_Image style="DISPLAY: none"
onclick="this.style.display='none'; document.getElementById('_417_751_Closed_Text').style.display='none'; document.getElementById('_417_751_Open_Image').style.display='inline'; document.getElementById('_417_751_Open_Text').style.display='inline';"
alt="" src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/ContractedSubBlock.gif"
align=top> </SPAN><SPAN id=_417_751_Closed_Text
style="BORDER-RIGHT: rgb(128,128,128) 1px solid; BORDER-TOP: rgb(128,128,128) 1px solid; DISPLAY: none; BORDER-LEFT: rgb(128,128,128) 1px solid; BORDER-BOTTOM: rgb(128,128,128) 1px solid; BACKGROUND-COLOR: rgb(255,255,255)">...</SPAN><SPAN
id=_417_751_Open_Text><SPAN style="COLOR: rgb(0,0,0)">{<BR><IMG alt=""
src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/InBlock.gif"
align=top> </SPAN><SPAN
style="COLOR: rgb(0,128,0)">//</SPAN><SPAN
style="COLOR: rgb(0,128,0)"> 计算从pos+1开始的全排列sub<BR><IMG alt=""
src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/InBlock.gif"
align=top> </SPAN><SPAN
style="COLOR: rgb(0,128,0)">//</SPAN><SPAN
style="COLOR: rgb(0,128,0)"> 然后就sub的每一项,计算出pos位置开始的全排列</SPAN><SPAN
style="COLOR: rgb(0,128,0)"><BR><IMG alt=""
src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/InBlock.gif"
align=top></SPAN><SPAN
style="COLOR: rgb(0,0,0)"> Permutation sub </SPAN><SPAN
style="COLOR: rgb(0,0,0)">=</SPAN><SPAN
style="COLOR: rgb(0,0,0)"> permute(templet, pos</SPAN><SPAN
style="COLOR: rgb(0,0,0)">+</SPAN><SPAN style="COLOR: rgb(0,0,0)">1</SPAN><SPAN
style="COLOR: rgb(0,0,0)">);<BR><IMG alt=""
src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/InBlock.gif"
align=top> </SPAN><SPAN
style="COLOR: rgb(0,0,255)">for</SPAN><SPAN
style="COLOR: rgb(0,0,0)"> (PmtIterator iter </SPAN><SPAN
style="COLOR: rgb(0,0,0)">=</SPAN><SPAN
style="COLOR: rgb(0,0,0)"> sub.begin(); iter </SPAN><SPAN
style="COLOR: rgb(0,0,0)">!=</SPAN><SPAN
style="COLOR: rgb(0,0,0)"> sub.end(); </SPAN><SPAN
style="COLOR: rgb(0,0,0)">++</SPAN><SPAN style="COLOR: rgb(0,0,0)">iter)<BR><IMG
id=_586_748_Open_Image
onclick="this.style.display='none'; document.getElementById('_586_748_Open_Text').style.display='none'; document.getElementById('_586_748_Closed_Image').style.display='inline'; document.getElementById('_586_748_Closed_Text').style.display='inline';"
alt=""
src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/ExpandedSubBlockStart.gif"
align=top><IMG id=_586_748_Closed_Image style="DISPLAY: none"
onclick="this.style.display='none'; document.getElementById('_586_748_Closed_Text').style.display='none'; document.getElementById('_586_748_Open_Image').style.display='inline'; document.getElementById('_586_748_Open_Text').style.display='inline';"
alt="" src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/ContractedSubBlock.gif"
align=top> </SPAN><SPAN
id=_586_748_Closed_Text
style="BORDER-RIGHT: rgb(128,128,128) 1px solid; BORDER-TOP: rgb(128,128,128) 1px solid; DISPLAY: none; BORDER-LEFT: rgb(128,128,128) 1px solid; BORDER-BOTTOM: rgb(128,128,128) 1px solid; BACKGROUND-COLOR: rgb(255,255,255)">...</SPAN><SPAN
id=_586_748_Open_Text><SPAN style="COLOR: rgb(0,0,0)">{<BR><IMG alt=""
src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/InBlock.gif"
align=top> </SPAN><SPAN
style="COLOR: rgb(0,0,255)">for</SPAN><SPAN
style="COLOR: rgb(0,0,0)"> (</SPAN><SPAN
style="COLOR: rgb(0,0,255)">string</SPAN><SPAN
style="COLOR: rgb(0,0,0)">::size_type pos1 </SPAN><SPAN
style="COLOR: rgb(0,0,0)">=</SPAN><SPAN
style="COLOR: rgb(0,0,0)"> </SPAN><SPAN
style="COLOR: rgb(0,0,0)">0</SPAN><SPAN
style="COLOR: rgb(0,0,0)">; pos1 </SPAN><SPAN
style="COLOR: rgb(0,0,0)"><=</SPAN><SPAN
style="COLOR: rgb(0,0,0)"> iter</SPAN><SPAN
style="COLOR: rgb(0,0,0)">-></SPAN><SPAN
style="COLOR: rgb(0,0,0)">size(); </SPAN><SPAN
style="COLOR: rgb(0,0,0)">++</SPAN><SPAN style="COLOR: rgb(0,0,0)">pos1)<BR><IMG
id=_657_744_Open_Image
onclick="this.style.display='none'; document.getElementById('_657_744_Open_Text').style.display='none'; document.getElementById('_657_744_Closed_Image').style.display='inline'; document.getElementById('_657_744_Closed_Text').style.display='inline';"
alt=""
src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/ExpandedSubBlockStart.gif"
align=top><IMG id=_657_744_Closed_Image style="DISPLAY: none"
onclick="this.style.display='none'; document.getElementById('_657_744_Closed_Text').style.display='none'; document.getElementById('_657_744_Open_Image').style.display='inline'; document.getElementById('_657_744_Open_Text').style.display='inline';"
alt="" src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/ContractedSubBlock.gif"
align=top> </SPAN><SPAN
id=_657_744_Closed_Text
style="BORDER-RIGHT: rgb(128,128,128) 1px solid; BORDER-TOP: rgb(128,128,128) 1px solid; DISPLAY: none; BORDER-LEFT: rgb(128,128,128) 1px solid; BORDER-BOTTOM: rgb(128,128,128) 1px solid; BACKGROUND-COLOR: rgb(255,255,255)">...</SPAN><SPAN
id=_657_744_Open_Text><SPAN style="COLOR: rgb(0,0,0)">{<BR><IMG alt=""
src="字符串全排列(迅雷笔试题) - sinall的专栏 - CSDNBlog.files/InBlock.gif"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -