﻿<?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++博客-codepeng-随笔分类-ACM程序</title><link>http://www.cppblog.com/codepeng/category/16792.html</link><description /><language>zh-cn</language><lastBuildDate>Wed, 14 Dec 2011 07:01:53 GMT</lastBuildDate><pubDate>Wed, 14 Dec 2011 07:01:53 GMT</pubDate><ttl>60</ttl><item><title>fzu OJ Problem 2064 找位置</title><link>http://www.cppblog.com/codepeng/archive/2011/12/13/162057.html</link><dc:creator>acpeng</dc:creator><author>acpeng</author><pubDate>Tue, 13 Dec 2011 14:06:00 GMT</pubDate><guid>http://www.cppblog.com/codepeng/archive/2011/12/13/162057.html</guid><wfw:comment>http://www.cppblog.com/codepeng/comments/162057.html</wfw:comment><comments>http://www.cppblog.com/codepeng/archive/2011/12/13/162057.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/codepeng/comments/commentRss/162057.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/codepeng/services/trackbacks/162057.html</trackback:ping><description><![CDATA[又刷一道水题，地址：<a href="http://acm.fzu.edu.cn/problem.php?pid=2064">http://acm.fzu.edu.cn/problem.php?pid=2064</a><br /><br />内容不复述，直接code
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><img id="Code_Closed_Image_220528" onclick="this.style.display='none'; Code_Closed_Text_220528.style.display='none'; Code_Open_Image_220528.style.display='inline'; Code_Open_Text_220528.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" width="11" height="16"><img style="display: none" id="Code_Open_Image_220528" onclick="this.style.display='none'; Code_Open_Text_220528.style.display='none'; Code_Closed_Image_220528.style.display='inline'; Code_Closed_Text_220528.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" width="11" height="16"><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Code_Closed_Text_220528"></span><span style="display: none" id="Code_Open_Text_220528"><br /><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">stdio.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;data[</span><span style="color: #000000">103</span><span style="color: #000000">][</span><span style="color: #000000">103</span><span style="color: #000000">];<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;flg_1,flg_2;<br /></span><span style="color: #008000">//</span><span style="color: #008000">搜索data[i][j]&nbsp;~&nbsp;data[i][j+w-1],若符合，返回1;否则返回0，flg_1为最后一个1的位置</span><span style="color: #008000"><br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;search(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a[],</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;j,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;w)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">j</span><span style="color: #000000">+</span><span style="color: #000000">w</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">;i</span><span style="color: #000000">&gt;=</span><span style="color: #000000">j;i</span><span style="color: #000000">--</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(a[i]</span><span style="color: #000000">!=</span><span style="color: #000000">0</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flg_1</span><span style="color: #000000">=</span><span style="color: #000000">i;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br />}<br /></span><span style="color: #008000">//</span><span style="color: #008000">找出data数据第&nbsp;i&nbsp;行data[i][j]之后的第一个1的位置，返回之间的0的个数</span><span style="color: #008000"><br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;find1behind(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a[],</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;j,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;m)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i,cont</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;j</span><span style="color: #000000">+</span><span style="color: #000000">i</span><span style="color: #000000">&lt;=</span><span style="color: #000000">m;j</span><span style="color: #000000">++</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(a[j</span><span style="color: #000000">+</span><span style="color: #000000">i]</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)cont</span><span style="color: #000000">++</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;flg_2</span><span style="color: #000000">=</span><span style="color: #000000">j</span><span style="color: #000000">+</span><span style="color: #000000">i;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;cont;<br />}<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;T,N,M,W,i,j,tmp,cont;<br />&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">T);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(T</span><span style="color: #000000">--</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d%d%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">N,</span><span style="color: #000000">&amp;</span><span style="color: #000000">M,</span><span style="color: #000000">&amp;</span><span style="color: #000000">W);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">N;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(j</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">M;j</span><span style="color: #000000">++</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">data[i][j]);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cont</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">N;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(j</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">M</span><span style="color: #000000">-</span><span style="color: #000000">W;j</span><span style="color: #000000">++</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp</span><span style="color: #000000">=</span><span style="color: #000000">search(data[i],j,W);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(tmp</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j</span><span style="color: #000000">=</span><span style="color: #000000">flg_1;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cont</span><span style="color: #000000">++</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cont</span><span style="color: #000000">+=</span><span style="color: #000000">find1behind(data[i],j</span><span style="color: #000000">+</span><span style="color: #000000">W,M</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j</span><span style="color: #000000">=</span><span style="color: #000000">flg_2;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d\n</span><span style="color: #000000">"</span><span style="color: #000000">,cont);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&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 />}</span></span></div><br /><br /><img src ="http://www.cppblog.com/codepeng/aggbug/162057.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/codepeng/" target="_blank">acpeng</a> 2011-12-13 22:06 <a href="http://www.cppblog.com/codepeng/archive/2011/12/13/162057.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDU  2084  数塔</title><link>http://www.cppblog.com/codepeng/archive/2011/10/03/157404.html</link><dc:creator>acpeng</dc:creator><author>acpeng</author><pubDate>Mon, 03 Oct 2011 04:16:00 GMT</pubDate><guid>http://www.cppblog.com/codepeng/archive/2011/10/03/157404.html</guid><wfw:comment>http://www.cppblog.com/codepeng/comments/157404.html</wfw:comment><comments>http://www.cppblog.com/codepeng/archive/2011/10/03/157404.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/codepeng/comments/commentRss/157404.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/codepeng/services/trackbacks/157404.html</trackback:ping><description><![CDATA[题目链接：<a href="http://acm.hdu.edu.cn/showproblem.php?pid=2084">http://acm.hdu.edu.cn/showproblem.php?pid=2084</a><br /><img src="http://acm.hdu.edu.cn/data/images/2084-1.jpg"  alt="" /><br /><br /><span style="color: red">经典入门级DP，自底向上，层层递进。（所谓的记忆化搜索）
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">stdio.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #0000ff">#define</span><span style="color: #000000">&nbsp;max(a,b)&nbsp;(a)&gt;(b)?(a):(b)</span><span style="color: #000000"><br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a[</span><span style="color: #000000">103</span><span style="color: #000000">][</span><span style="color: #000000">103</span><span style="color: #000000">];<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;t,n,i,j;<br />&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">t);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(t</span><span style="color: #000000">--</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">n);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">n;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(j</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">i;j</span><span style="color: #000000">++</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">a[i][j]);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">n</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">;i</span><span style="color: #000000">&gt;</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">--</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(j</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">i;j</span><span style="color: #000000">++</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[i</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">][j]</span><span style="color: #000000">+=</span><span style="color: #000000">max(a[i][j],a[i][j</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">]);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d\n</span><span style="color: #000000">"</span><span style="color: #000000">,a[</span><span style="color: #000000">0</span><span style="color: #000000">][</span><span style="color: #000000">0</span><span style="color: #000000">]);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&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 />}</span></div><br /></span> <img src ="http://www.cppblog.com/codepeng/aggbug/157404.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/codepeng/" target="_blank">acpeng</a> 2011-10-03 12:16 <a href="http://www.cppblog.com/codepeng/archive/2011/10/03/157404.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDU 1160  ZOJ 1108  FatMouse's Speed</title><link>http://www.cppblog.com/codepeng/archive/2011/10/03/157386.html</link><dc:creator>acpeng</dc:creator><author>acpeng</author><pubDate>Sun, 02 Oct 2011 19:24:00 GMT</pubDate><guid>http://www.cppblog.com/codepeng/archive/2011/10/03/157386.html</guid><wfw:comment>http://www.cppblog.com/codepeng/comments/157386.html</wfw:comment><comments>http://www.cppblog.com/codepeng/archive/2011/10/03/157386.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/codepeng/comments/commentRss/157386.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/codepeng/services/trackbacks/157386.html</trackback:ping><description><![CDATA[<div>题目链接：<a href="http://acm.hdu.edu.cn/showproblem.php?pid=1160">http://acm.hdu.edu.cn/showproblem.php?pid=1160</a><br />
<div class="panel_title" align="left"><strong style="color: red">Problem Description</strong></div>
<div class="panel_content">FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take the data on a collection of mice and put as large a subset of this data as possible into a sequence so that the weights are increasing, but the speeds are decreasing.<br /></div>
<div class="panel_bottom">&nbsp;</div>
<div class="panel_title" align="left"><strong style="color: red">Input</strong></div>
<div class="panel_content">Input contains data for a bunch of mice, one mouse per line, terminated by end of file.<br />The data for a particular mouse will consist of a pair of integers: the first representing its size in grams and the second representing its speed in centimeters per second. Both integers are between 1 and 10000. The data in each test case will contain information for at most 1000 mice.<br />Two mice may have the same weight, the same speed, or even the same weight and speed. <br /></div>
<div class="panel_title" align="left"><strong style="color: red">Output</strong></div>
<div class="panel_content">Your program should output a sequence of lines of data; the first line should contain a number n; the remaining n lines should each contain a single positive integer (each one representing a mouse). If these n integers are m[1], m[2],..., m[n] then it must be the case that <br /><br /><span style="color: #0000ff"><strong>W[m[1]] &lt; W[m[2]] &lt; ... &lt; W[m[n]]</strong></span><br /><br />and <br /><br /><span style="color: #0000ff"><strong>S[m[1]] &gt; S[m[2]] &gt; ... &gt; S[m[n]]</strong></span><br /><br />In order for the answer to be correct, n should be as large as possible.<br />All inequalities are strict: weights must be strictly increasing, and speeds must be strictly decreasing. There may be many correct outputs for a given input, your program only needs to find one. <br /></div>
<div class="panel_bottom">&nbsp;<br /><strong style="color: #ff0000">Sample Input</strong></div>
<div class="panel_content"><pre><div style="font-family: Courier New,Courier,monospace">6008 1300
6000 2100
500 2000
1000 4000
1100 3000
6000 2000
8000 1400
6000 1200
2000 1900<br /><br /><br /><br /><br /></div></pre></div>
<div class="panel_title" align="left"><strong style="color: #ff0000">Sample Output</strong></div>
<div class="panel_content"><pre><div style="font-family: Courier New,Courier,monospace">4
4
5<span>
9
7</span><br /><span>解题思</span><span>路：</span><br /><span style="color: #008000">首先根据weight的数值由小到大排序，然后再以speed为标准，求最长下降子序列，思路还是DP，但是要标记子序列的下标</span><br /><span style="color: #008000">麻烦多了，我的做</span><span style="color: #008000">法：</span><br /><span style="color: #008000">定义MaxInclud</span><span style="color: #008000">eEnd数组，令MaxIncludeEnd[i]表示以a[i]结尾的最长下降子序列的长度，那么</span><br /><span style="color: #008000">MaxIncludeEnd[i]=max{ MaxIncludeEnd[i] , a[j]&gt;a[i] ? (MaxIncludeEnd[j]+1) ：-1; }</span><br /><span style="color: #008000">其中j=0:i-1;MaxIncludeEnd[i]的初始值为1,每一个i结束后用max和MaxIncludeEnd[i]比较，更新max和下标max_flg。</span><br /><span style="color: #008000">因为要标记下标，在计算MaxIncludeEnd[i]后，用flg[i]表示以a[i]结尾的最长下降子序列的前一个元素的下标，这样计算完</span><br /><span style="color: #008000">MaxIncludeEnd[n]并更新完max和max_flg以后，循环递推一次就可以得到所有的元素下标，即flg[max_flg],flg[ flg[max_flg] ],&#8230;&#8230;</span><br /><span style="color: #008000">当然这里的下标是逆向的，要设置个新的数组来将其逆转。</span><br /><span style="color: #008000">ps：如果从后往前计算最长上升子序列</span><span style="color: #008000">，那就不</span><span style="color: #008000">必如此麻烦，</span><span style="color: #008000">减少空间。<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><img id="Code_Closed_Image_032916" onclick="this.style.display='none'; Code_Closed_Text_032916.style.display='none'; Code_Open_Image_032916.style.display='inline'; Code_Open_Text_032916.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" width="11" height="16"><img style="display: none" id="Code_Open_Image_032916" onclick="this.style.display='none'; Code_Open_Text_032916.style.display='none'; Code_Closed_Image_032916.style.display='inline'; Code_Closed_Text_032916.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" width="11" height="16"><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Code_Closed_Text_032916">code</span><span style="display: none" id="Code_Open_Text_032916"><br /><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br />#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">algorithm</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></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 /></span><span style="color: #0000ff">struct</span><span style="color: #000000">&nbsp;mouse<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;weight;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;speed;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;num;<br />}mice[</span><span style="color: #000000">1002</span><span style="color: #000000">];<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;MaxIncludeEnd[</span><span style="color: #000000">1002</span><span style="color: #000000">],flg[</span><span style="color: #000000">1002</span><span style="color: #000000">],rst[</span><span style="color: #000000">1002</span><span style="color: #000000">];<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;cmp(</span><span style="color: #0000ff">struct</span><span style="color: #000000">&nbsp;mouse&nbsp;a,</span><span style="color: #0000ff">struct</span><span style="color: #000000">&nbsp;mouse&nbsp;b)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(a.weight</span><span style="color: #000000">&lt;</span><span style="color: #000000">b.weight)</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br />&nbsp;&nbsp;&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 />}<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;w,s,i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">,j,k,size,max,max_flg;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">w,</span><span style="color: #000000">&amp;</span><span style="color: #000000">s)</span><span style="color: #000000">!=</span><span style="color: #000000">EOF)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mice[i].weight</span><span style="color: #000000">=</span><span style="color: #000000">w;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mice[i].speed</span><span style="color: #000000">=</span><span style="color: #000000">s;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mice[i].num</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 />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;size</span><span style="color: #000000">=</span><span style="color: #000000">i;<br />&nbsp;&nbsp;&nbsp;&nbsp;sort(mice,mice</span><span style="color: #000000">+</span><span style="color: #000000">size,cmp);<br />&nbsp;&nbsp;&nbsp;&nbsp;max</span><span style="color: #000000">=</span><span style="color: #000000">max_flg</span><span style="color: #000000">=</span><span style="color: #000000">flg[</span><span style="color: #000000">0</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i</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">size;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MaxIncludeEnd[i]</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(j</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">i;j</span><span style="color: #000000">++</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(mice[i].speed</span><span style="color: #000000">&lt;</span><span style="color: #000000">mice[j].speed&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;mice[i].weight</span><span style="color: #000000">&gt;</span><span style="color: #000000">mice[j].weight&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;MaxIncludeEnd[j]</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">&gt;</span><span style="color: #000000">MaxIncludeEnd[i])<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MaxIncludeEnd[i]</span><span style="color: #000000">=</span><span style="color: #000000">MaxIncludeEnd[j]</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flg[i]</span><span style="color: #000000">=</span><span style="color: #000000">j;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(max</span><span style="color: #000000">&lt;</span><span style="color: #000000">MaxIncludeEnd[i])<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;max</span><span style="color: #000000">=</span><span style="color: #000000">MaxIncludeEnd[i];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;max_flg</span><span style="color: #000000">=</span><span style="color: #000000">i;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d\n</span><span style="color: #000000">"</span><span style="color: #000000">,max);<br />&nbsp;&nbsp;&nbsp;&nbsp;k</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(max</span><span style="color: #000000">--</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rst[k</span><span style="color: #000000">++</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">max_flg;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;max_flg</span><span style="color: #000000">=</span><span style="color: #000000">flg[max_flg];<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(k</span><span style="color: #000000">--</span><span style="color: #000000">;k</span><span style="color: #000000">&gt;=</span><span style="color: #000000">0</span><span style="color: #000000">;k</span><span style="color: #000000">--</span><span style="color: #000000">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d\n</span><span style="color: #000000">"</span><span style="color: #000000">,mice[rst[k]].num);<br />&nbsp;&nbsp;&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 />}</span></span></div><br /></span><br /><br /></div></pre></div></div> <img src ="http://www.cppblog.com/codepeng/aggbug/157386.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/codepeng/" target="_blank">acpeng</a> 2011-10-03 03:24 <a href="http://www.cppblog.com/codepeng/archive/2011/10/03/157386.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDU 1087  Super Jumping</title><link>http://www.cppblog.com/codepeng/archive/2011/10/03/157380.html</link><dc:creator>acpeng</dc:creator><author>acpeng</author><pubDate>Sun, 02 Oct 2011 17:28:00 GMT</pubDate><guid>http://www.cppblog.com/codepeng/archive/2011/10/03/157380.html</guid><wfw:comment>http://www.cppblog.com/codepeng/comments/157380.html</wfw:comment><comments>http://www.cppblog.com/codepeng/archive/2011/10/03/157380.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/codepeng/comments/commentRss/157380.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/codepeng/services/trackbacks/157380.html</trackback:ping><description><![CDATA[<div>题目链接：<a href="http://acm.hdu.edu.cn/showproblem.php?pid=1087">http://acm.hdu.edu.cn/showproblem.php?pid=1087</a><br />
<div class="panel_title" align="left"><strong style="color: #3366ff">Problem Description</strong></div>
<div class="panel_content">Nowadays, a kind of chess game called &#8220;Super Jumping! Jumping! Jumping!&#8221; is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now.<br /><br />
<center><img src="http://acm.hdu.edu.cn/data/images/1087-1.jpg"  alt="" /></center><br />The game can be played by two or more than two players. It consists of a chessboard（棋盘）and some chessmen（棋子）, and all chessmen are marked by a positive integer or &#8220;start&#8221; or &#8220;end&#8221;. The player starts from start-point and must jumps into end-point finally. In the course of jumping, the player will visit the chessmen in the path, but everyone must jumps from one chessman to another absolutely bigger (you can assume start-point is a minimum and end-point is a maximum.). And all players cannot go backwards. One jumping can go from a chessman to next, also can go across many chessmen, and even you can straightly get to end-point from start-point. Of course you get zero point in this situation. A player is a winner if and only if he can get a bigger score according to his jumping solution. Note that your score comes from the sum of value on the chessmen in you jumping path.<br />Your task is to output the maximum value according to the given chessmen list.<br /></div>
<div class="panel_title" align="left"><span style="color: #3366ff"><strong>Input</strong></span></div>
<div class="panel_content">Input contains multiple test cases. Each test case is described in a line as follow:<br />N value_1 value_2 &#8230;value_N <br />It is guarantied that N is not more than 1000 and all value_i are in the range of 32-int.<br />A test case starting with 0 terminates the input and this test case is not to be processed.<br /></div>
<div class="panel_title" align="left"><strong style="color: #3366ff">Output</strong></div>
<div class="panel_content">For each case, print the maximum according to rules, and one line one case.<br /><br /><span style="color: #ff0000"><strong>Sample Input</strong></span></div>
<div class="panel_content"><pre><div style="font-family: Courier New,Courier,monospace">3 1 3 2
4 1 2 3 4
4 3 3 2 1
0<br /></div></pre></div>
<div class="panel_title" align="left"><strong style="color: #ff0000">Sample Output</strong></div>
<div class="panel_content"><pre><div style="font-family: Courier New,Courier,monospace">4
10
3<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />典型的入门级DP题，解题思路：<br />定义MaxIncludeEnd数组，令MaxIncludeEnd[i]表示以a[i]结尾的最大和，那么<br />MaxIncludeEnd[i]=max{ MaxIncludeEnd[i] , a[j]&lt;a[i] ? (MaxIncludeEnd[j]+a[i]) ：-1; }<br />其中j=0 to i-1;MaxIncludeEnd[i]的初始值为a[i]。<br /><div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">stdio.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a[</span><span style="color: #000000">1003</span><span style="color: #000000">],MaxIncludeEnd[</span><span style="color: #000000">1003</span><span style="color: #000000">];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_62_455_Open_Image" onclick="this.style.display='none'; Codehighlighter1_62_455_Open_Text.style.display='none'; Codehighlighter1_62_455_Closed_Image.style.display='inline'; Codehighlighter1_62_455_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_62_455_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_62_455_Closed_Text.style.display='none'; Codehighlighter1_62_455_Open_Image.style.display='inline'; Codehighlighter1_62_455_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_62_455_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_62_455_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n,max,i,j;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">n),n)<br /><img id="Codehighlighter1_106_442_Open_Image" onclick="this.style.display='none'; Codehighlighter1_106_442_Open_Text.style.display='none'; Codehighlighter1_106_442_Closed_Image.style.display='inline'; Codehighlighter1_106_442_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_106_442_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_106_442_Closed_Text.style.display='none'; Codehighlighter1_106_442_Open_Image.style.display='inline'; Codehighlighter1_106_442_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_106_442_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_106_442_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">n;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img id="Codehighlighter1_129_181_Open_Image" onclick="this.style.display='none'; Codehighlighter1_129_181_Open_Text.style.display='none'; Codehighlighter1_129_181_Closed_Image.style.display='inline'; Codehighlighter1_129_181_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_129_181_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_129_181_Closed_Text.style.display='none'; Codehighlighter1_129_181_Open_Image.style.display='inline'; Codehighlighter1_129_181_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_129_181_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_129_181_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">a[i]);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MaxIncludeEnd[i]</span><span style="color: #000000">=</span><span style="color: #000000">a[i];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;max</span><span style="color: #000000">=</span><span style="color: #000000">MaxIncludeEnd[</span><span style="color: #000000">0</span><span style="color: #000000">];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">n;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img id="Codehighlighter1_228_416_Open_Image" onclick="this.style.display='none'; Codehighlighter1_228_416_Open_Text.style.display='none'; Codehighlighter1_228_416_Closed_Image.style.display='inline'; Codehighlighter1_228_416_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_228_416_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_228_416_Closed_Text.style.display='none'; Codehighlighter1_228_416_Open_Image.style.display='inline'; Codehighlighter1_228_416_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_228_416_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_228_416_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(j</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">i;j</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img id="Codehighlighter1_253_363_Open_Image" onclick="this.style.display='none'; Codehighlighter1_253_363_Open_Text.style.display='none'; Codehighlighter1_253_363_Closed_Image.style.display='inline'; Codehighlighter1_253_363_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_253_363_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_253_363_Closed_Text.style.display='none'; Codehighlighter1_253_363_Open_Image.style.display='inline'; Codehighlighter1_253_363_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_253_363_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_253_363_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(a[j]</span><span style="color: #000000">&lt;</span><span style="color: #000000">a[i]&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;MaxIncludeEnd[j]</span><span style="color: #000000">+</span><span style="color: #000000">a[i]</span><span style="color: #000000">&gt;</span><span style="color: #000000">MaxIncludeEnd[i])<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MaxIncludeEnd[i]</span><span style="color: #000000">=</span><span style="color: #000000">MaxIncludeEnd[j]</span><span style="color: #000000">+</span><span style="color: #000000">a[i];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(max</span><span style="color: #000000">&lt;</span><span style="color: #000000">MaxIncludeEnd[i])max</span><span style="color: #000000">=</span><span style="color: #000000">MaxIncludeEnd[i];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d\n</span><span style="color: #000000">"</span><span style="color: #000000">,max);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&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 align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span></div><br /><br /><br /></div></pre></div></div><img src ="http://www.cppblog.com/codepeng/aggbug/157380.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/codepeng/" target="_blank">acpeng</a> 2011-10-03 01:28 <a href="http://www.cppblog.com/codepeng/archive/2011/10/03/157380.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ZOJ1292 , HDU  1047 Integer Inquiry</title><link>http://www.cppblog.com/codepeng/archive/2011/09/05/155171.html</link><dc:creator>acpeng</dc:creator><author>acpeng</author><pubDate>Mon, 05 Sep 2011 15:22:00 GMT</pubDate><guid>http://www.cppblog.com/codepeng/archive/2011/09/05/155171.html</guid><wfw:comment>http://www.cppblog.com/codepeng/comments/155171.html</wfw:comment><comments>http://www.cppblog.com/codepeng/archive/2011/09/05/155171.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/codepeng/comments/commentRss/155171.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/codepeng/services/trackbacks/155171.html</trackback:ping><description><![CDATA[<div>大数相加，字符模拟<br />题目链接：<br />ZOJ：<a href="http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1292">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1292</a><br />HDU：<a href="http://acm.hdu.edu.cn/showproblem.php?pid=1047">http://acm.hdu.edu.cn/showproblem.php?pid=1047</a><br /><br /><strong>Description<br /></strong>One of the first users of BIT's new supercomputer was Chip Diller. He extended his exploration of powers of 3 to go from 0 to 333 and he explored taking various sums of those numbers. 
<p>``This supercomputer is great,'' remarked Chip. ``I only wish Timothy were here to see these results.'' (Chip moved to a new apartment, once one became available on the third floor of the Lemon Sky apartments on Third Street.) </p>
<p><br /><strong>Input</strong><br />The input will consist of at most 100 lines of text, each of which contains a single VeryLongInteger. Each VeryLongInteger will be 100 or fewer characters in length, and will only contain digits (no VeryLongInteger will be negative). </p>
<p>The final input line will contain a single zero on a line by itself. </p>
<p><br /><strong>Output</strong><br />Your program should output the sum of the VeryLongIntegers given in the input. </p>
<p><br /><strong>This problem contains multiple test cases!</strong></p>
<p>The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.</p>
<p>The output format consists of N output blocks. There is a blank line between output blocks.</p>
<p><strong><br />Sample Input</strong></p>1<br /><br />
<p>123456789012345678901234567890<br />123456789012345678901234567890<br />123456789012345678901234567890<br />0</p>
<p><strong><br />Sample Output</strong></p>
<p>370370367037037036703703703670<br /><br />AC代码：</p>
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img id="Codehighlighter1_0_39_Open_Image" onclick="this.style.display='none'; Codehighlighter1_0_39_Open_Text.style.display='none'; Codehighlighter1_0_39_Closed_Image.style.display='inline'; Codehighlighter1_0_39_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_0_39_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_0_39_Closed_Text.style.display='none'; Codehighlighter1_0_39_Open_Image.style.display='inline'; Codehighlighter1_0_39_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_0_39_Closed_Text">/**/</span><span id="Codehighlighter1_0_39_Open_Text"><span style="color: #008000">/*</span><span style="color: #008000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />Accepted&nbsp;1047&nbsp;0MS&nbsp;188K&nbsp;1256&nbsp;B&nbsp;C++&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" /></span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">stdio.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">string</span><span style="color: #000000">.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">#define</span><span style="color: #000000">&nbsp;MaxSize&nbsp;1000</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;FunBigAdd(</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">str1,</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">str2);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_149_558_Open_Image" onclick="this.style.display='none'; Codehighlighter1_149_558_Open_Text.style.display='none'; Codehighlighter1_149_558_Closed_Image.style.display='inline'; Codehighlighter1_149_558_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_149_558_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_149_558_Closed_Text.style.display='none'; Codehighlighter1_149_558_Open_Image.style.display='inline'; Codehighlighter1_149_558_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_149_558_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_149_558_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;IntStr[MaxSize]</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">\0</span><span style="color: #000000">"</span><span style="color: #000000">,str[MaxSize]</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">\0</span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;T,i;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">T);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(T</span><span style="color: #000000">--</span><span style="color: #000000">)<br /><img id="Codehighlighter1_239_545_Open_Image" onclick="this.style.display='none'; Codehighlighter1_239_545_Open_Text.style.display='none'; Codehighlighter1_239_545_Closed_Image.style.display='inline'; Codehighlighter1_239_545_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_239_545_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_239_545_Closed_Text.style.display='none'; Codehighlighter1_239_545_Open_Image.style.display='inline'; Codehighlighter1_239_545_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_239_545_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_239_545_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(str,</span><span style="color: #000000">0</span><span style="color: #000000">,MaxSize);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%s</span><span style="color: #000000">"</span><span style="color: #000000">,IntStr);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(strcmp(IntStr,</span><span style="color: #000000">"</span><span style="color: #000000">0</span><span style="color: #000000">"</span><span style="color: #000000">)</span><span style="color: #000000">!=</span><span style="color: #000000">0</span><span style="color: #000000">)<br /><img id="Codehighlighter1_321_403_Open_Image" onclick="this.style.display='none'; Codehighlighter1_321_403_Open_Text.style.display='none'; Codehighlighter1_321_403_Closed_Image.style.display='inline'; Codehighlighter1_321_403_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_321_403_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_321_403_Closed_Text.style.display='none'; Codehighlighter1_321_403_Open_Image.style.display='inline'; Codehighlighter1_321_403_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_321_403_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_321_403_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FunBigAdd(str,IntStr);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(IntStr,</span><span style="color: #000000">0</span><span style="color: #000000">,MaxSize);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%s</span><span style="color: #000000">"</span><span style="color: #000000">,IntStr);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(str[i]</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">0</span><span style="color: #000000">'</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;str[i]</span><span style="color: #000000">!=</span><span style="color: #000000">'</span><span style="color: #000000">\0</span><span style="color: #000000">'</span><span style="color: #000000">)i</span><span style="color: #000000">++</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(str[i]</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">\0</span><span style="color: #000000">'</span><span style="color: #000000">)printf(</span><span style="color: #000000">"</span><span style="color: #000000">0\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%s\n</span><span style="color: #000000">"</span><span style="color: #000000">,str</span><span style="color: #000000">+</span><span style="color: #000000">i);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(T</span><span style="color: #000000">!=</span><span style="color: #000000">0</span><span style="color: #000000">)printf(</span><span style="color: #000000">"</span><span style="color: #000000">\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&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 align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;strRevg(</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">str)<br /><img id="Codehighlighter1_584_728_Open_Image" onclick="this.style.display='none'; Codehighlighter1_584_728_Open_Text.style.display='none'; Codehighlighter1_584_728_Closed_Image.style.display='inline'; Codehighlighter1_584_728_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_584_728_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_584_728_Closed_Text.style.display='none'; Codehighlighter1_584_728_Open_Image.style.display='inline'; Codehighlighter1_584_728_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_584_728_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_584_728_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;temp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;lgth</span><span style="color: #000000">=</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">)strlen(str)</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i</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">lgth</span><span style="color: #000000">-</span><span style="color: #000000">i;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img id="Codehighlighter1_658_726_Open_Image" onclick="this.style.display='none'; Codehighlighter1_658_726_Open_Text.style.display='none'; Codehighlighter1_658_726_Closed_Image.style.display='inline'; Codehighlighter1_658_726_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_658_726_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_658_726_Closed_Text.style.display='none'; Codehighlighter1_658_726_Open_Image.style.display='inline'; Codehighlighter1_658_726_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_658_726_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_658_726_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;temp</span><span style="color: #000000">=*</span><span style="color: #000000">(str</span><span style="color: #000000">+</span><span style="color: #000000">i);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">(str</span><span style="color: #000000">+</span><span style="color: #000000">i)</span><span style="color: #000000">=*</span><span style="color: #000000">(str</span><span style="color: #000000">+</span><span style="color: #000000">lgth</span><span style="color: #000000">-</span><span style="color: #000000">i);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">(str</span><span style="color: #000000">+</span><span style="color: #000000">lgth</span><span style="color: #000000">-</span><span style="color: #000000">i)</span><span style="color: #000000">=</span><span style="color: #000000">temp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;FunBigAdd(</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">str1,</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">str2)<br /><img id="Codehighlighter1_768_1171_Open_Image" onclick="this.style.display='none'; Codehighlighter1_768_1171_Open_Text.style.display='none'; Codehighlighter1_768_1171_Closed_Image.style.display='inline'; Codehighlighter1_768_1171_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_768_1171_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_768_1171_Closed_Text.style.display='none'; Codehighlighter1_768_1171_Open_Image.style.display='inline'; Codehighlighter1_768_1171_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_768_1171_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_768_1171_Open_Text"><span style="color: #000000">{&nbsp;&nbsp;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">,dec</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">,tmp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;strRevg(str1);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;strRevg(str2);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(</span><span style="color: #000000">*</span><span style="color: #000000">(str1</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">\0</span><span style="color: #000000">'</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">(str2</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">\0</span><span style="color: #000000">'</span><span style="color: #000000">)<br /><img id="Codehighlighter1_869_1100_Open_Image" onclick="this.style.display='none'; Codehighlighter1_869_1100_Open_Text.style.display='none'; Codehighlighter1_869_1100_Closed_Image.style.display='inline'; Codehighlighter1_869_1100_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_869_1100_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_869_1100_Closed_Text.style.display='none'; Codehighlighter1_869_1100_Open_Image.style.display='inline'; Codehighlighter1_869_1100_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_869_1100_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_869_1100_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #000000">*</span><span style="color: #000000">(str1</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">\0</span><span style="color: #000000">'</span><span style="color: #000000">)<br /><img id="Codehighlighter1_896_940_Open_Image" onclick="this.style.display='none'; Codehighlighter1_896_940_Open_Text.style.display='none'; Codehighlighter1_896_940_Closed_Image.style.display='inline'; Codehighlighter1_896_940_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_896_940_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_896_940_Closed_Text.style.display='none'; Codehighlighter1_896_940_Open_Image.style.display='inline'; Codehighlighter1_896_940_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_896_940_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_896_940_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">(str1</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">0</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">(str1</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">)</span><span style="color: #000000">=</span><span style="color: #000000">'</span><span style="color: #000000">\0</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #000000">*</span><span style="color: #000000">(str2</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">\0</span><span style="color: #000000">'</span><span style="color: #000000">)<br /><img id="Codehighlighter1_967_1011_Open_Image" onclick="this.style.display='none'; Codehighlighter1_967_1011_Open_Text.style.display='none'; Codehighlighter1_967_1011_Closed_Image.style.display='inline'; Codehighlighter1_967_1011_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_967_1011_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_967_1011_Closed_Text.style.display='none'; Codehighlighter1_967_1011_Open_Image.style.display='inline'; Codehighlighter1_967_1011_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_967_1011_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_967_1011_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">(str2</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">0</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">(str2</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">)</span><span style="color: #000000">=</span><span style="color: #000000">'</span><span style="color: #000000">\0</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp</span><span style="color: #000000">=*</span><span style="color: #000000">(str1</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">0</span><span style="color: #000000">'</span><span style="color: #000000">+</span><span style="color: #000000">(</span><span style="color: #000000">*</span><span style="color: #000000">(str2</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">0</span><span style="color: #000000">'</span><span style="color: #000000">)</span><span style="color: #000000">+</span><span style="color: #000000">dec;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">(str1</span><span style="color: #000000">+</span><span style="color: #000000">i)</span><span style="color: #000000">=</span><span style="color: #000000">tmp</span><span style="color: #000000">%</span><span style="color: #000000">10</span><span style="color: #000000">+</span><span style="color: #000000">'</span><span style="color: #000000">0</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dec</span><span style="color: #000000">=</span><span style="color: #000000">tmp</span><span style="color: #000000">/</span><span style="color: #000000">10</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(dec</span><span style="color: #000000">!=</span><span style="color: #000000">0</span><span style="color: #000000">)&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">(str1</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">=</span><span style="color: #000000">dec</span><span style="color: #000000">+</span><span style="color: #000000">'</span><span style="color: #000000">0</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">(str1</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">\0</span><span style="color: #000000">'</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;strRevg(str1);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span></div>
<p><br /><br /></p></div><img src ="http://www.cppblog.com/codepeng/aggbug/155171.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/codepeng/" target="_blank">acpeng</a> 2011-09-05 23:22 <a href="http://www.cppblog.com/codepeng/archive/2011/09/05/155171.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ZOJ 1061  Web Navigation_数据结构_栈</title><link>http://www.cppblog.com/codepeng/archive/2011/09/05/155165.html</link><dc:creator>acpeng</dc:creator><author>acpeng</author><pubDate>Mon, 05 Sep 2011 14:47:00 GMT</pubDate><guid>http://www.cppblog.com/codepeng/archive/2011/09/05/155165.html</guid><wfw:comment>http://www.cppblog.com/codepeng/comments/155165.html</wfw:comment><comments>http://www.cppblog.com/codepeng/archive/2011/09/05/155165.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/codepeng/comments/commentRss/155165.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/codepeng/services/trackbacks/155165.html</trackback:ping><description><![CDATA[<a href="http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=61">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=61</a><br />数据结构，用C写的栈，不用STL确实复杂多了，WA了几次~<br />Standard web browsers contain features to move backward and forward among the pages recently visited. One way to implement these features is to use two stacks to keep track of the pages that can be reached by moving backward and forward. In this problem, you are asked to implement this. 
<p>The following commands need to be supported:</p>
<p><strong>BACK</strong>: Push the current page on the top of the forward stack. Pop the page from the top of the backward stack, making it the new current page. If the backward stack is empty, the command is ignored.</p>
<p><strong>FORWARD</strong>: Push the current page on the top of the backward stack. Pop the page from the top of the forward stack, making it the new current page. If the forward stack is empty, the command is ignored.</p>
<p><strong>VISIT &lt;url&gt;</strong>: Push the current page on the top of the backward stack, and make the URL specified the new current page. The forward stack is emptied.</p>
<p><strong>QUIT</strong>: Quit the browser.</p>
<p>Assume that the browser initially loads the web page at the URL http://www.acm.org/<br /><br /></p>
<p><br /><strong>This problem contains multiple test cases!</strong></p>
<p>The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.</p>
<p>The output format consists of N output blocks. There is a blank line between output blocks.</p>
<p><br /><strong>Input</strong></p>
<p>Input is a sequence of commands. The command keywords BACK, FORWARD, VISIT, and QUIT are all in uppercase. URLs have no whitespace and have at most 70 characters. You may assume that no problem instance requires more than 100 elements in each stack at any time. The end of input is indicated by the QUIT command.<br /><br /></p>
<p><strong>Output</strong></p>
<p>For each command other than QUIT, print the URL of the current page after the command is executed if the command is not ignored. Otherwise, print "Ignored". The output for each command should be printed on its own line. No output is produced for the QUIT command.<br /><br /></p>
<p><strong>Sample Input</strong></p>
<p>1</p>
<p>VISIT http://acm.ashland.edu/<br />VISIT http://acm.baylor.edu/acmicpc/<br />BACK<br />BACK<br />BACK<br />FORWARD<br />VISIT http://www.ibm.com/<br />BACK<br />BACK<br />FORWARD<br />FORWARD<br />FORWARD<br />QUIT<br /><br /></p>
<p><strong>Sample Output</strong></p>
<p>http://acm.ashland.edu/<br />http://acm.baylor.edu/acmicpc/<br />http://acm.ashland.edu/<br />http://www.acm.org/<br />Ignored<br />http://acm.ashland.edu/<br />http://www.ibm.com/<br />http://acm.ashland.edu/<br />http://www.acm.org/<br />http://acm.ashland.edu/<br />http://www.ibm.com/<br />Ignored<br /><br />AC代码：</p>
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">stdio.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">string</span><span style="color: #000000">.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">malloc.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">#define</span><span style="color: #000000">&nbsp;StackSize&nbsp;105</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />typedef&nbsp;</span><span style="color: #0000ff">struct</span><span style="color: #000000"><br /><img id="Codehighlighter1_93_133_Open_Image" onclick="this.style.display='none'; Codehighlighter1_93_133_Open_Text.style.display='none'; Codehighlighter1_93_133_Closed_Image.style.display='inline'; Codehighlighter1_93_133_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_93_133_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_93_133_Closed_Text.style.display='none'; Codehighlighter1_93_133_Open_Image.style.display='inline'; Codehighlighter1_93_133_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_93_133_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_93_133_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;elemt[StackSize][</span><span style="color: #000000">73</span><span style="color: #000000">];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;top;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000">Stack;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;InitStack(Stack&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">S)<br /><img id="Codehighlighter1_166_182_Open_Image" onclick="this.style.display='none'; Codehighlighter1_166_182_Open_Text.style.display='none'; Codehighlighter1_166_182_Closed_Image.style.display='inline'; Codehighlighter1_166_182_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_166_182_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_166_182_Closed_Text.style.display='none'; Codehighlighter1_166_182_Open_Image.style.display='inline'; Codehighlighter1_166_182_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_166_182_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_166_182_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;S</span><span style="color: #000000">-&gt;</span><span style="color: #000000">top</span><span style="color: #000000">=-</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;ElemtNum(Stack&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">S)<br /><img id="Codehighlighter1_207_229_Open_Image" onclick="this.style.display='none'; Codehighlighter1_207_229_Open_Text.style.display='none'; Codehighlighter1_207_229_Closed_Image.style.display='inline'; Codehighlighter1_207_229_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_207_229_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_207_229_Closed_Text.style.display='none'; Codehighlighter1_207_229_Open_Image.style.display='inline'; Codehighlighter1_207_229_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_207_229_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_207_229_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;(S</span><span style="color: #000000">-&gt;</span><span style="color: #000000">top)</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;IsFull(Stack&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">S)<br /><img id="Codehighlighter1_252_288_Open_Image" onclick="this.style.display='none'; Codehighlighter1_252_288_Open_Text.style.display='none'; Codehighlighter1_252_288_Closed_Image.style.display='inline'; Codehighlighter1_252_288_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_252_288_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_252_288_Closed_Text.style.display='none'; Codehighlighter1_252_288_Open_Image.style.display='inline'; Codehighlighter1_252_288_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_252_288_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_252_288_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">(S</span><span style="color: #000000">-&gt;</span><span style="color: #000000">top</span><span style="color: #000000">==</span><span style="color: #000000">StackSize</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">?</span><span style="color: #000000">1</span><span style="color: #000000">:</span><span style="color: #000000">0</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;PushStack(Stack&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">S,</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">x)<br /><img id="Codehighlighter1_322_462_Open_Image" onclick="this.style.display='none'; Codehighlighter1_322_462_Open_Text.style.display='none'; Codehighlighter1_322_462_Closed_Image.style.display='inline'; Codehighlighter1_322_462_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_322_462_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_322_462_Closed_Text.style.display='none'; Codehighlighter1_322_462_Open_Image.style.display='inline'; Codehighlighter1_322_462_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_322_462_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_322_462_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(IsFull(S))&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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 align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;S</span><span style="color: #000000">-&gt;</span><span style="color: #000000">top</span><span style="color: #000000">++</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;memset(S</span><span style="color: #000000">-&gt;</span><span style="color: #000000">elemt[S</span><span style="color: #000000">-&gt;</span><span style="color: #000000">top],</span><span style="color: #000000">'</span><span style="color: #000000">\0</span><span style="color: #000000">'</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(S</span><span style="color: #000000">-&gt;</span><span style="color: #000000">elemt[S</span><span style="color: #000000">-&gt;</span><span style="color: #000000">top]));<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;strcpy(S</span><span style="color: #000000">-&gt;</span><span style="color: #000000">elemt[S</span><span style="color: #000000">-&gt;</span><span style="color: #000000">top],x);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;PopStack(Stack&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">S,</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">x)<br /><img id="Codehighlighter1_495_664_Open_Image" onclick="this.style.display='none'; Codehighlighter1_495_664_Open_Text.style.display='none'; Codehighlighter1_495_664_Closed_Image.style.display='inline'; Codehighlighter1_495_664_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_495_664_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_495_664_Closed_Text.style.display='none'; Codehighlighter1_495_664_Open_Image.style.display='inline'; Codehighlighter1_495_664_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_495_664_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_495_664_Open_Text"><span style="color: #000000">{&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(ElemtNum(S)</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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 align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;memset(x,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(x));<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcpy(x,S</span><span style="color: #000000">-&gt;</span><span style="color: #000000">elemt[S</span><span style="color: #000000">-&gt;</span><span style="color: #000000">top]);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;memset(S</span><span style="color: #000000">-&gt;</span><span style="color: #000000">elemt[S</span><span style="color: #000000">-&gt;</span><span style="color: #000000">top],</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(S</span><span style="color: #000000">-&gt;</span><span style="color: #000000">elemt[S</span><span style="color: #000000">-&gt;</span><span style="color: #000000">top]));<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;S</span><span style="color: #000000">-&gt;</span><span style="color: #000000">top</span><span style="color: #000000">--</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;GetTopElemt(Stack&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">S,</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">x)<br /><img id="Codehighlighter1_700_804_Open_Image" onclick="this.style.display='none'; Codehighlighter1_700_804_Open_Text.style.display='none'; Codehighlighter1_700_804_Closed_Image.style.display='inline'; Codehighlighter1_700_804_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_700_804_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_700_804_Closed_Text.style.display='none'; Codehighlighter1_700_804_Open_Image.style.display='inline'; Codehighlighter1_700_804_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_700_804_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_700_804_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(ElemtNum(S)</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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 align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(x,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(x));<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcpy(x,S</span><span style="color: #000000">-&gt;</span><span style="color: #000000">elemt[S</span><span style="color: #000000">-&gt;</span><span style="color: #000000">top]);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_817_1936_Open_Image" onclick="this.style.display='none'; Codehighlighter1_817_1936_Open_Text.style.display='none'; Codehighlighter1_817_1936_Closed_Image.style.display='inline'; Codehighlighter1_817_1936_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_817_1936_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_817_1936_Closed_Text.style.display='none'; Codehighlighter1_817_1936_Open_Image.style.display='inline'; Codehighlighter1_817_1936_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_817_1936_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_817_1936_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;Stack&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">sBack,</span><span style="color: #000000">*</span><span style="color: #000000">sForward;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;sBack</span><span style="color: #000000">=</span><span style="color: #000000">(Stack&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">)malloc(</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(Stack));<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;sForward</span><span style="color: #000000">=</span><span style="color: #000000">(Stack&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">)malloc(</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(Stack));<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;T;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;str[</span><span style="color: #000000">73</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">\0</span><span style="color: #000000">"</span><span style="color: #000000">,comd[</span><span style="color: #000000">8</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">\0</span><span style="color: #000000">"</span><span style="color: #000000">,tmp[</span><span style="color: #000000">73</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">\0</span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">T);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(T</span><span style="color: #000000">--</span><span style="color: #000000">)<br /><img id="Codehighlighter1_1010_1894_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1010_1894_Open_Text.style.display='none'; Codehighlighter1_1010_1894_Closed_Image.style.display='inline'; Codehighlighter1_1010_1894_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1010_1894_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1010_1894_Closed_Text.style.display='none'; Codehighlighter1_1010_1894_Open_Image.style.display='inline'; Codehighlighter1_1010_1894_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1010_1894_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1010_1894_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InitStack(sBack);&nbsp;InitStack(sForward);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PushStack(sBack,</span><span style="color: #000000">"</span><span style="color: #000000">http://www.acm.org/</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(</span><span style="color: #000000">1</span><span style="color: #000000">)<br /><img id="Codehighlighter1_1108_1866_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1108_1866_Open_Text.style.display='none'; Codehighlighter1_1108_1866_Closed_Image.style.display='inline'; Codehighlighter1_1108_1866_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1108_1866_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1108_1866_Closed_Text.style.display='none'; Codehighlighter1_1108_1866_Open_Image.style.display='inline'; Codehighlighter1_1108_1866_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1108_1866_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1108_1866_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(comd,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(comd));<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%s</span><span style="color: #000000">"</span><span style="color: #000000">,comd);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(strcmp(comd,</span><span style="color: #000000">"</span><span style="color: #000000">BACK</span><span style="color: #000000">"</span><span style="color: #000000">)</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)<br /><img id="Codehighlighter1_1196_1396_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1196_1396_Open_Text.style.display='none'; Codehighlighter1_1196_1396_Closed_Image.style.display='inline'; Codehighlighter1_1196_1396_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1196_1396_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1196_1396_Closed_Text.style.display='none'; Codehighlighter1_1196_1396_Open_Image.style.display='inline'; Codehighlighter1_1196_1396_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1196_1396_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1196_1396_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(ElemtNum(sBack)</span><span style="color: #000000">==</span><span style="color: #000000">1</span><span style="color: #000000">)<br /><img id="Codehighlighter1_1229_1277_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1229_1277_Open_Text.style.display='none'; Codehighlighter1_1229_1277_Closed_Image.style.display='inline'; Codehighlighter1_1229_1277_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1229_1277_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1229_1277_Closed_Text.style.display='none'; Codehighlighter1_1229_1277_Open_Image.style.display='inline'; Codehighlighter1_1229_1277_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1229_1277_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1229_1277_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">Ignored\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">continue</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PopStack(sBack,tmp);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PushStack(sForward,tmp);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(GetTopElemt(sBack,tmp)</span><span style="color: #000000">==</span><span style="color: #000000">1</span><span style="color: #000000">)<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%s\n</span><span style="color: #000000">"</span><span style="color: #000000">,tmp);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(strcmp(comd,</span><span style="color: #000000">"</span><span style="color: #000000">FORWARD</span><span style="color: #000000">"</span><span style="color: #000000">)</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)<br /><img id="Codehighlighter1_1439_1642_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1439_1642_Open_Text.style.display='none'; Codehighlighter1_1439_1642_Closed_Image.style.display='inline'; Codehighlighter1_1439_1642_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1439_1642_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1439_1642_Closed_Text.style.display='none'; Codehighlighter1_1439_1642_Open_Image.style.display='inline'; Codehighlighter1_1439_1642_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1439_1642_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1439_1642_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(ElemtNum(sForward)</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)<br /><img id="Codehighlighter1_1475_1523_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1475_1523_Open_Text.style.display='none'; Codehighlighter1_1475_1523_Closed_Image.style.display='inline'; Codehighlighter1_1475_1523_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1475_1523_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1475_1523_Closed_Text.style.display='none'; Codehighlighter1_1475_1523_Open_Image.style.display='inline'; Codehighlighter1_1475_1523_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1475_1523_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1475_1523_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">Ignored\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">continue</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PopStack(sForward,tmp);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PushStack(sBack,tmp);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(GetTopElemt(sBack,tmp)</span><span style="color: #000000">==</span><span style="color: #000000">1</span><span style="color: #000000">)<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%s\n</span><span style="color: #000000">"</span><span style="color: #000000">,tmp);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(strcmp(comd,</span><span style="color: #000000">"</span><span style="color: #000000">VISIT</span><span style="color: #000000">"</span><span style="color: #000000">)</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)<br /><img id="Codehighlighter1_1683_1816_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1683_1816_Open_Text.style.display='none'; Codehighlighter1_1683_1816_Closed_Image.style.display='inline'; Codehighlighter1_1683_1816_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1683_1816_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1683_1816_Closed_Text.style.display='none'; Codehighlighter1_1683_1816_Open_Image.style.display='inline'; Codehighlighter1_1683_1816_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1683_1816_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1683_1816_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(str,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(str));<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%s</span><span style="color: #000000">"</span><span style="color: #000000">,str);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%s\n</span><span style="color: #000000">"</span><span style="color: #000000">,str);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PushStack(sBack,str);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InitStack(sForward);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(strcmp(comd,</span><span style="color: #000000">"</span><span style="color: #000000">QUIT</span><span style="color: #000000">"</span><span style="color: #000000">)</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&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 align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(T</span><span style="color: #000000">&gt;</span><span style="color: #000000">0</span><span style="color: #000000">)&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;free(sBack);free(sForward);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&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 align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span></div>
<p><br /></p><img src ="http://www.cppblog.com/codepeng/aggbug/155165.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/codepeng/" target="_blank">acpeng</a> 2011-09-05 22:47 <a href="http://www.cppblog.com/codepeng/archive/2011/09/05/155165.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDU  1862 EXCEL排序</title><link>http://www.cppblog.com/codepeng/archive/2011/09/05/155160.html</link><dc:creator>acpeng</dc:creator><author>acpeng</author><pubDate>Mon, 05 Sep 2011 14:20:00 GMT</pubDate><guid>http://www.cppblog.com/codepeng/archive/2011/09/05/155160.html</guid><wfw:comment>http://www.cppblog.com/codepeng/comments/155160.html</wfw:comment><comments>http://www.cppblog.com/codepeng/archive/2011/09/05/155160.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/codepeng/comments/commentRss/155160.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/codepeng/services/trackbacks/155160.html</trackback:ping><description><![CDATA[<a href="http://acm.hdu.edu.cn/showproblem.php?pid=1862">http://acm.hdu.edu.cn/showproblem.php?pid=1862</a><br />结构体排序，C++的algorithm，写三个cmp即可<br />不过以这个数据的话，何必<span style="color: #008000"><strong>TimeLimit=5000ms</strong></span>~~
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstring</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">algorithm</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  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 align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />typedef&nbsp;</span><span style="color: #0000ff">struct</span><span style="color: #000000">&nbsp;infor<br /><img id="Codehighlighter1_97_143_Open_Image" onclick="this.style.display='none'; Codehighlighter1_97_143_Open_Text.style.display='none'; Codehighlighter1_97_143_Closed_Image.style.display='inline'; Codehighlighter1_97_143_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_97_143_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_97_143_Closed_Text.style.display='none'; Codehighlighter1_97_143_Open_Image.style.display='inline'; Codehighlighter1_97_143_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_97_143_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_97_143_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;stu_num[</span><span style="color: #000000">7</span><span style="color: #000000">];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;name[</span><span style="color: #000000">9</span><span style="color: #000000">];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;scor;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000">stu;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />stu&nbsp;data[</span><span style="color: #000000">100002</span><span style="color: #000000">];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;cmp1(stu&nbsp;a,stu&nbsp;b)<br /><img id="Codehighlighter1_189_246_Open_Image" onclick="this.style.display='none'; Codehighlighter1_189_246_Open_Text.style.display='none'; Codehighlighter1_189_246_Closed_Image.style.display='inline'; Codehighlighter1_189_246_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_189_246_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_189_246_Closed_Text.style.display='none'; Codehighlighter1_189_246_Open_Image.style.display='inline'; Codehighlighter1_189_246_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_189_246_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_189_246_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(strcmp(a.stu_num,b.stu_num)</span><span style="color: #000000">&lt;</span><span style="color: #000000">0</span><span style="color: #000000">)</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&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 align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;cmp2(stu&nbsp;a,stu&nbsp;b)<br /><img id="Codehighlighter1_270_407_Open_Image" onclick="this.style.display='none'; Codehighlighter1_270_407_Open_Text.style.display='none'; Codehighlighter1_270_407_Closed_Image.style.display='inline'; Codehighlighter1_270_407_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_270_407_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_270_407_Closed_Text.style.display='none'; Codehighlighter1_270_407_Open_Image.style.display='inline'; Codehighlighter1_270_407_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_270_407_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_270_407_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(strcmp(a.name,b.name)</span><span style="color: #000000">&lt;</span><span style="color: #000000">0</span><span style="color: #000000">)</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(strcmp(a.name,b.name)</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)<br /><img id="Codehighlighter1_346_394_Open_Image" onclick="this.style.display='none'; Codehighlighter1_346_394_Open_Text.style.display='none'; Codehighlighter1_346_394_Closed_Image.style.display='inline'; Codehighlighter1_346_394_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_346_394_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_346_394_Closed_Text.style.display='none'; Codehighlighter1_346_394_Open_Image.style.display='inline'; Codehighlighter1_346_394_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_346_394_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_346_394_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(strcmp(a.stu_num,b.stu_num)</span><span style="color: #000000">&lt;</span><span style="color: #000000">0</span><span style="color: #000000">)</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&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 align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;cmp3(stu&nbsp;a,stu&nbsp;b)<br /><img id="Codehighlighter1_431_548_Open_Image" onclick="this.style.display='none'; Codehighlighter1_431_548_Open_Text.style.display='none'; Codehighlighter1_431_548_Closed_Image.style.display='inline'; Codehighlighter1_431_548_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_431_548_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_431_548_Closed_Text.style.display='none'; Codehighlighter1_431_548_Open_Image.style.display='inline'; Codehighlighter1_431_548_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_431_548_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_431_548_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(a.scor</span><span style="color: #000000">&lt;</span><span style="color: #000000">b.scor)</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(a.scor</span><span style="color: #000000">==</span><span style="color: #000000">b.scor)<br /><img id="Codehighlighter1_487_535_Open_Image" onclick="this.style.display='none'; Codehighlighter1_487_535_Open_Text.style.display='none'; Codehighlighter1_487_535_Closed_Image.style.display='inline'; Codehighlighter1_487_535_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_487_535_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_487_535_Closed_Text.style.display='none'; Codehighlighter1_487_535_Open_Image.style.display='inline'; Codehighlighter1_487_535_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_487_535_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_487_535_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(strcmp(a.stu_num,b.stu_num)</span><span style="color: #000000">&lt;</span><span style="color: #000000">0</span><span style="color: #000000">)</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&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 align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_561_934_Open_Image" onclick="this.style.display='none'; Codehighlighter1_561_934_Open_Text.style.display='none'; Codehighlighter1_561_934_Closed_Image.style.display='inline'; Codehighlighter1_561_934_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_561_934_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_561_934_Closed_Text.style.display='none'; Codehighlighter1_561_934_Open_Image.style.display='inline'; Codehighlighter1_561_934_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_561_934_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_561_934_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n,c,i,test</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">n,</span><span style="color: #000000">&amp;</span><span style="color: #000000">c),n)<br /><img id="Codehighlighter1_613_921_Open_Image" onclick="this.style.display='none'; Codehighlighter1_613_921_Open_Text.style.display='none'; Codehighlighter1_613_921_Closed_Image.style.display='inline'; Codehighlighter1_613_921_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_613_921_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_613_921_Closed_Text.style.display='none'; Codehighlighter1_613_921_Open_Image.style.display='inline'; Codehighlighter1_613_921_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_613_921_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_613_921_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">n;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%s%s%d</span><span style="color: #000000">"</span><span style="color: #000000">,data[i].stu_num,data[i].name,</span><span style="color: #000000">&amp;</span><span style="color: #000000">data[i].scor);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(c</span><span style="color: #000000">==</span><span style="color: #000000">1</span><span style="color: #000000">)sort(data,data</span><span style="color: #000000">+</span><span style="color: #000000">n,cmp1);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(c</span><span style="color: #000000">==</span><span style="color: #000000">2</span><span style="color: #000000">)sort(data,data</span><span style="color: #000000">+</span><span style="color: #000000">n,cmp2);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;sort(data,data</span><span style="color: #000000">+</span><span style="color: #000000">n,cmp3);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">Case&nbsp;%d:\n</span><span style="color: #000000">"</span><span style="color: #000000">,test</span><span style="color: #000000">++</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">n;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%s&nbsp;%s&nbsp;%d\n</span><span style="color: #000000">"</span><span style="color: #000000">,data[i].stu_num,data[i].name,data[i].scor);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&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 align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span></div><br /><img src ="http://www.cppblog.com/codepeng/aggbug/155160.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/codepeng/" target="_blank">acpeng</a> 2011-09-05 22:20 <a href="http://www.cppblog.com/codepeng/archive/2011/09/05/155160.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>POJ 2273  An Excel-lent Problem</title><link>http://www.cppblog.com/codepeng/archive/2011/09/05/155158.html</link><dc:creator>acpeng</dc:creator><author>acpeng</author><pubDate>Mon, 05 Sep 2011 13:53:00 GMT</pubDate><guid>http://www.cppblog.com/codepeng/archive/2011/09/05/155158.html</guid><wfw:comment>http://www.cppblog.com/codepeng/comments/155158.html</wfw:comment><comments>http://www.cppblog.com/codepeng/archive/2011/09/05/155158.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/codepeng/comments/commentRss/155158.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/codepeng/services/trackbacks/155158.html</trackback:ping><description><![CDATA[<div class="plm"></div>
<p class="pst">把整数转化为excel对应的列值<a href="http://poj.org/problem?id=2273"><strong>http://poj.org/problem?id=2273</strong></a><br /><strong>Description</strong></p>
<div lang="en-US" class="ptx">A certain spreadsheet program labels the columns of a spreadsheet using letters. Column 1 is labeled as ``A", column 2 as ``B", ..., column 26 as ``Z". When the number of columns is greater than 26, another letter is used. For example, column 27 is ``AA", column 28 is ``AB" and column 52 is ``AZ". It follows that column 53 would be ``BA" and so on. Similarly, when column ``ZZ" is reached, the next column would be ``AAA", then ``AAB" and so on. <br /><br />The rows in the spreadsheet are labeled using the row number. Rows start at 1. <br /><br />The designation for a particular cell within the spreadsheet is created by combining the column label with the row label. For example, the upper-left most cell would be ``A1". The cell at column 55 row 23 would be ``BC23". <br /><br />You will write a program that converts numeric row and column values into the spreadsheet designation. </div>
<p class="pst"><strong style="color: #3366ff">Input</strong></p>
<div lang="en-US" class="ptx">Input consists of lines of the form: RnCm. n represents the row number [1,300000000] and m represents the column number, 1&lt;=m&lt;=300000000. The values n and m define a single cell on the spreadsheet. Input terminates with the line: R0C0 (that is, n and m are 0). There will be no leading zeroes or extra spaces in the input. <br /></div>
<p class="pst"><span style="color: #3366ff">Output</span></p>
<div lang="en-US" class="ptx">For each line of input (except the terminating line), you will print out the spreadsheet designation for the specified cell as described above.</div>
<p class="pst"><strong style="color: #ff0000">Sample Input</strong></p><pre class="sio">R1C1
R3C1
R1C3
R299999999C26
R52C52
R53C17576
R53C17602
R0C0
</pre>
<p class="pst"><span style="color: #ff0000"><strong>Sample Output</strong></span></p><pre class="sio">A1
A3
C1
Z299999999
AZ52
YYZ53
YZZ53
</pre>
<p class="pst"><strong style="color: #008000">Source</strong></p>
<div lang="en-US" class="ptx"><a href="http://poj.org/searchproblem?field=source&amp;key=Greater+New+York+2004">Greater New York 2004</a><br /><br />进制转化问题，把列数改成26进制输出，分别用A,B...Z代替1,2,3...这里base[0]='Z'，表示n与26余数为0时的取值，但进位问题需要注意，分余数是否为0两种情况分析。<br />代码： 
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /><span style="color: #000000">#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">stdio.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">#define</span><span style="color: #000000">&nbsp;R&nbsp;26</span><span style="color: #000000"><br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">base</span><span style="color: #000000">[</span><span style="color: #000000">30</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">ZABCDEFGHIJKLMNOPQRSTUVWXYZ</span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;fun(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;N)<br /><img id="Codehighlighter1_92_259_Open_Image" onclick="this.style.display='none'; Codehighlighter1_92_259_Open_Text.style.display='none'; Codehighlighter1_92_259_Closed_Image.style.display='inline'; Codehighlighter1_92_259_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_92_259_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_92_259_Closed_Text.style.display='none'; Codehighlighter1_92_259_Open_Image.style.display='inline'; Codehighlighter1_92_259_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_92_259_Closed_Text"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_92_259_Open_Text"><span style="color: #000000">{<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">,j;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;str[</span><span style="color: #000000">10</span><span style="color: #000000">];<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(N</span><span style="color: #000000">&gt;</span><span style="color: #000000">R)<br /><img id="Codehighlighter1_136_192_Open_Image" onclick="this.style.display='none'; Codehighlighter1_136_192_Open_Text.style.display='none'; Codehighlighter1_136_192_Closed_Image.style.display='inline'; Codehighlighter1_136_192_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_136_192_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_136_192_Closed_Text.style.display='none'; Codehighlighter1_136_192_Open_Image.style.display='inline'; Codehighlighter1_136_192_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_136_192_Closed_Text"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_136_192_Open_Text"><span style="color: #000000">{<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str[i</span><span style="color: #000000">++</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #0000ff">base</span><span style="color: #000000">[N</span><span style="color: #000000">%</span><span style="color: #000000">R];<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;N</span><span style="color: #000000">=</span><span style="color: #000000">N</span><span style="color: #000000">%</span><span style="color: #000000">R</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">?</span><span style="color: #000000">N</span><span style="color: #000000">/</span><span style="color: #000000">R</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">:N</span><span style="color: #000000">/</span><span style="color: #000000">R;<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;str[i]</span><span style="color: #000000">=</span><span style="color: #0000ff">base</span><span style="color: #000000">[N];<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(j</span><span style="color: #000000">=</span><span style="color: #000000">i;j</span><span style="color: #000000">&gt;=</span><span style="color: #000000">0</span><span style="color: #000000">;j</span><span style="color: #000000">--</span><span style="color: #000000">)<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%c</span><span style="color: #000000">"</span><span style="color: #000000">,str[j]);<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" />}</span></span><span style="color: #000000"><br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_272_409_Open_Image" onclick="this.style.display='none'; Codehighlighter1_272_409_Open_Text.style.display='none'; Codehighlighter1_272_409_Closed_Image.style.display='inline'; Codehighlighter1_272_409_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_272_409_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_272_409_Closed_Text.style.display='none'; Codehighlighter1_272_409_Open_Image.style.display='inline'; Codehighlighter1_272_409_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_272_409_Closed_Text"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_272_409_Open_Text"><span style="color: #000000">{<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;m,n;<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%*c%d%*c%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">m,</span><span style="color: #000000">&amp;</span><span style="color: #000000">n)</span><span style="color: #000000">!=</span><span style="color: #000000">EOF)<br /><img id="Codehighlighter1_324_396_Open_Image" onclick="this.style.display='none'; Codehighlighter1_324_396_Open_Text.style.display='none'; Codehighlighter1_324_396_Closed_Image.style.display='inline'; Codehighlighter1_324_396_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_324_396_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_324_396_Closed_Text.style.display='none'; Codehighlighter1_324_396_Open_Image.style.display='inline'; Codehighlighter1_324_396_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_324_396_Closed_Text"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_324_396_Open_Text"><span style="color: #000000">{<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;getchar();<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(m</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;n</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fun(n);<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d\n</span><span style="color: #000000">"</span><span style="color: #000000">,m);<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&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 alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" />}</span></span></div><br /></div><img src ="http://www.cppblog.com/codepeng/aggbug/155158.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/codepeng/" target="_blank">acpeng</a> 2011-09-05 21:53 <a href="http://www.cppblog.com/codepeng/archive/2011/09/05/155158.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDU 1166敌兵布阵</title><link>http://www.cppblog.com/codepeng/archive/2011/09/01/154891.html</link><dc:creator>acpeng</dc:creator><author>acpeng</author><pubDate>Thu, 01 Sep 2011 09:14:00 GMT</pubDate><guid>http://www.cppblog.com/codepeng/archive/2011/09/01/154891.html</guid><wfw:comment>http://www.cppblog.com/codepeng/comments/154891.html</wfw:comment><comments>http://www.cppblog.com/codepeng/archive/2011/09/01/154891.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/codepeng/comments/commentRss/154891.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/codepeng/services/trackbacks/154891.html</trackback:ping><description><![CDATA[<div>题目链接：<a href="http://acm.hdu.edu.cn/showproblem.php?pid=1166">http://acm.hdu.edu.cn/showproblem.php?pid=1166</a><br />初学线段树，本想些个树，写了一半实在是觉得没必要，此题直接用数组模拟，果断AC，1Y~~~
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">stdio.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">string</span><span style="color: #000000">.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;data[</span><span style="color: #000000">50003</span><span style="color: #000000">];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_65_629_Open_Image" onclick="this.style.display='none'; Codehighlighter1_65_629_Open_Text.style.display='none'; Codehighlighter1_65_629_Closed_Image.style.display='inline'; Codehighlighter1_65_629_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_65_629_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_65_629_Closed_Text.style.display='none'; Codehighlighter1_65_629_Open_Image.style.display='inline'; Codehighlighter1_65_629_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_65_629_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_65_629_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;T,N,i,cont</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;cd_1,cd_2,sum;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;comd[</span><span style="color: #000000">7</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">\0</span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">T);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(T</span><span style="color: #000000">--</span><span style="color: #000000">)<br /><img id="Codehighlighter1_157_616_Open_Image" onclick="this.style.display='none'; Codehighlighter1_157_616_Open_Text.style.display='none'; Codehighlighter1_157_616_Closed_Image.style.display='inline'; Codehighlighter1_157_616_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_157_616_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_157_616_Closed_Text.style.display='none'; Codehighlighter1_157_616_Open_Image.style.display='inline'; Codehighlighter1_157_616_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_157_616_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_157_616_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">N);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">Case&nbsp;%d:\n</span><span style="color: #000000">"</span><span style="color: #000000">,cont);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cont</span><span style="color: #000000">++</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">N;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">data[i]);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%s</span><span style="color: #000000">"</span><span style="color: #000000">,comd);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(strcmp(comd,</span><span style="color: #000000">"</span><span style="color: #000000">End</span><span style="color: #000000">"</span><span style="color: #000000">)</span><span style="color: #000000">!=</span><span style="color: #000000">0</span><span style="color: #000000">)<br /><img id="Codehighlighter1_314_613_Open_Image" onclick="this.style.display='none'; Codehighlighter1_314_613_Open_Text.style.display='none'; Codehighlighter1_314_613_Closed_Image.style.display='inline'; Codehighlighter1_314_613_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_314_613_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_314_613_Closed_Text.style.display='none'; Codehighlighter1_314_613_Open_Image.style.display='inline'; Codehighlighter1_314_613_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_314_613_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_314_613_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">cd_1,</span><span style="color: #000000">&amp;</span><span style="color: #000000">cd_2);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(comd[</span><span style="color: #000000">0</span><span style="color: #000000">]</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">A</span><span style="color: #000000">'</span><span style="color: #000000">)<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data[cd_1</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">cd_2;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(comd[</span><span style="color: #000000">0</span><span style="color: #000000">]</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">S</span><span style="color: #000000">'</span><span style="color: #000000">)<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data[cd_1</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">cd_2;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(comd[</span><span style="color: #000000">0</span><span style="color: #000000">]</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">Q</span><span style="color: #000000">'</span><span style="color: #000000">)<br /><img id="Codehighlighter1_467_556_Open_Image" onclick="this.style.display='none'; Codehighlighter1_467_556_Open_Text.style.display='none'; Codehighlighter1_467_556_Closed_Image.style.display='inline'; Codehighlighter1_467_556_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_467_556_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_467_556_Closed_Text.style.display='none'; Codehighlighter1_467_556_Open_Image.style.display='inline'; Codehighlighter1_467_556_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_467_556_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_467_556_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">cd_1</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">cd_2;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum</span><span style="color: #000000">+=</span><span style="color: #000000">data[i];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d\n</span><span style="color: #000000">"</span><span style="color: #000000">,sum);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(comd,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(comd));<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%s</span><span style="color: #000000">"</span><span style="color: #000000">,comd);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&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 align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span></div><br /></div><img src ="http://www.cppblog.com/codepeng/aggbug/154891.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/codepeng/" target="_blank">acpeng</a> 2011-09-01 17:14 <a href="http://www.cppblog.com/codepeng/archive/2011/09/01/154891.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HDU 1022  Train Problem I_数据结构_栈</title><link>http://www.cppblog.com/codepeng/archive/2011/08/26/154443.html</link><dc:creator>acpeng</dc:creator><author>acpeng</author><pubDate>Fri, 26 Aug 2011 10:04:00 GMT</pubDate><guid>http://www.cppblog.com/codepeng/archive/2011/08/26/154443.html</guid><wfw:comment>http://www.cppblog.com/codepeng/comments/154443.html</wfw:comment><comments>http://www.cppblog.com/codepeng/archive/2011/08/26/154443.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/codepeng/comments/commentRss/154443.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/codepeng/services/trackbacks/154443.html</trackback:ping><description><![CDATA[<div>题目地址：<a href="http://acm.hdu.edu.cn/showproblem.php?pid=1022">http://acm.hdu.edu.cn/showproblem.php?pid=1022</a><br />
<div class="panel_title" align="left"><strong style="color: #0000ff">Problem Description</strong></div>
<div class="panel_content">&nbsp;&nbsp;&nbsp;&nbsp; As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all over the world ^v^). But here comes a problem, there is only one railway where all the trains stop. So all the trains come in from one side and get out from the other side. For this problem, if train A gets into the railway first, and then train B gets into the railway before train A leaves, train A can't leave until train B leaves. The pictures below figure out the problem. Now the problem for you is, there are at most 9 trains in the station, all the trains has an ID(numbered from 1 to n), the trains get into the railway in an order O1, your task is to determine whether the trains can get out in an order O2.<br /><img src="http://acm.hdu.edu.cn/data/images/1022-1.jpg"  alt="" /><img src="http://acm.hdu.edu.cn/data/images/1022-2.jpg"  alt="" /><img src="http://acm.hdu.edu.cn/data/images/1022-3.jpg"  alt="" /><br /></div>
<div class="panel_title" align="left"><strong style="color: #0000ff">Input</strong></div>
<div class="panel_content">The input contains several test cases. Each test case consists of an integer, the number of trains, and two strings, the order of the trains come in:O1, and the order of the trains leave:O2. The input is terminated by the end of file. More details in the Sample Input.</div>
<div class="panel_title" align="left"><span style="color: #0000ff"><strong>Output</strong></span></div>
<div class="panel_content">The output contains a string "No." if you can't exchange O2 to O1, or you should output a line contains "Yes.", and then output your way in exchanging the order(you should output "in" for a train getting into the railway, and "out" for a train getting out of the railway). Print a line contains "FINISH" after each test case. More details in the Sample Output.<br /></div>
<div class="panel_title" align="left"><span style="color: #0000ff"><strong>Sample Input</strong></span></div>
<div class="panel_content"><pre><div style="font-family: Courier New,Courier,monospace">3 123 321
3 123 312<br /></div></pre></div>
<div class="panel_title" align="left"><span style="color: #0000ff"><strong>Sample Output</strong></span></div>
<div class="panel_content"><pre><div style="font-family: Courier New,Courier,monospace">Yes.
in
in
in
out
out
out
FINISH
No.
FINISH
下面是代码，第一次使用C++的STL模板，用的很不熟练，不过没想到1Y就过了~~~YY。。。<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">cstdio</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">stack</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  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 align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_65_965_Open_Image" onclick="this.style.display='none'; Codehighlighter1_65_965_Open_Text.style.display='none'; Codehighlighter1_65_965_Closed_Image.style.display='inline'; Codehighlighter1_65_965_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_65_965_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_65_965_Closed_Text.style.display='none'; Codehighlighter1_65_965_Open_Image.style.display='inline'; Codehighlighter1_65_965_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_65_965_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_65_965_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i,j,k,n,ok,flg[</span><span style="color: #000000">22</span><span style="color: #000000">];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">in</span><span style="color: #000000">[</span><span style="color: #000000">10</span><span style="color: #000000">],</span><span style="color: #0000ff">out</span><span style="color: #000000">[</span><span style="color: #000000">10</span><span style="color: #000000">];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">n)</span><span style="color: #000000">!=</span><span style="color: #000000">EOF)<br /><img id="Codehighlighter1_155_949_Open_Image" onclick="this.style.display='none'; Codehighlighter1_155_949_Open_Text.style.display='none'; Codehighlighter1_155_949_Closed_Image.style.display='inline'; Codehighlighter1_155_949_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_155_949_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_155_949_Closed_Text.style.display='none'; Codehighlighter1_155_949_Open_Image.style.display='inline'; Codehighlighter1_155_949_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_155_949_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_155_949_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%s%s</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #0000ff">in</span><span style="color: #000000">,</span><span style="color: #0000ff">out</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stack</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">int</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;s;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">j</span><span style="color: #000000">=</span><span style="color: #000000">k</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;ok</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(j</span><span style="color: #000000">&lt;</span><span style="color: #000000">n)<br /><img id="Codehighlighter1_258_673_Open_Image" onclick="this.style.display='none'; Codehighlighter1_258_673_Open_Text.style.display='none'; Codehighlighter1_258_673_Closed_Image.style.display='inline'; Codehighlighter1_258_673_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_258_673_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_258_673_Closed_Text.style.display='none'; Codehighlighter1_258_673_Open_Image.style.display='inline'; Codehighlighter1_258_673_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_258_673_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_258_673_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #0000ff">in</span><span style="color: #000000">[i]</span><span style="color: #000000">==</span><span style="color: #0000ff">out</span><span style="color: #000000">[j])<br /><img id="Codehighlighter1_302_363_Open_Image" onclick="this.style.display='none'; Codehighlighter1_302_363_Open_Text.style.display='none'; Codehighlighter1_302_363_Closed_Image.style.display='inline'; Codehighlighter1_302_363_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_302_363_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_302_363_Closed_Text.style.display='none'; Codehighlighter1_302_363_Open_Image.style.display='inline'; Codehighlighter1_302_363_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_302_363_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_302_363_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flg[k</span><span style="color: #000000">++</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;flg[k</span><span style="color: #000000">++</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;i</span><span style="color: #000000">++</span><span style="color: #000000">;j</span><span style="color: #000000">++</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #000000">!</span><span style="color: #000000">s.empty()&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;s.top()</span><span style="color: #000000">==</span><span style="color: #000000">(</span><span style="color: #0000ff">out</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">'</span><span style="color: #000000">))<br /><img id="Codehighlighter1_434_488_Open_Image" onclick="this.style.display='none'; Codehighlighter1_434_488_Open_Text.style.display='none'; Codehighlighter1_434_488_Closed_Image.style.display='inline'; Codehighlighter1_434_488_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_434_488_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_434_488_Closed_Text.style.display='none'; Codehighlighter1_434_488_Open_Image.style.display='inline'; Codehighlighter1_434_488_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_434_488_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_434_488_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flg[k</span><span style="color: #000000">++</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;s.pop();j</span><span style="color: #000000">++</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(i</span><span style="color: #000000">&lt;</span><span style="color: #000000">n)<br /><img id="Codehighlighter1_527_589_Open_Image" onclick="this.style.display='none'; Codehighlighter1_527_589_Open_Text.style.display='none'; Codehighlighter1_527_589_Closed_Image.style.display='inline'; Codehighlighter1_527_589_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_527_589_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_527_589_Closed_Text.style.display='none'; Codehighlighter1_527_589_Open_Image.style.display='inline'; Codehighlighter1_527_589_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_527_589_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_527_589_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.push(</span><span style="color: #0000ff">in</span><span style="color: #000000">[i</span><span style="color: #000000">++</span><span style="color: #000000">]</span><span style="color: #000000">-</span><span style="color: #000000">'</span><span style="color: #000000">0</span><span style="color: #000000">'</span><span style="color: #000000">);flg[k</span><span style="color: #000000">++</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;<br /><img id="Codehighlighter1_621_663_Open_Image" onclick="this.style.display='none'; Codehighlighter1_621_663_Open_Text.style.display='none'; Codehighlighter1_621_663_Closed_Image.style.display='inline'; Codehighlighter1_621_663_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_621_663_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_621_663_Closed_Text.style.display='none'; Codehighlighter1_621_663_Open_Image.style.display='inline'; Codehighlighter1_621_663_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_621_663_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_621_663_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ok</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(ok</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)printf(</span><span style="color: #000000">"</span><span style="color: #000000">No.\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /><img id="Codehighlighter1_731_914_Open_Image" onclick="this.style.display='none'; Codehighlighter1_731_914_Open_Text.style.display='none'; Codehighlighter1_731_914_Closed_Image.style.display='inline'; Codehighlighter1_731_914_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_731_914_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_731_914_Closed_Text.style.display='none'; Codehighlighter1_731_914_Open_Image.style.display='inline'; Codehighlighter1_731_914_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_731_914_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_731_914_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">Yes.\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i</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">k;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img id="Codehighlighter1_805_904_Open_Image" onclick="this.style.display='none'; Codehighlighter1_805_904_Open_Text.style.display='none'; Codehighlighter1_805_904_Closed_Image.style.display='inline'; Codehighlighter1_805_904_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_805_904_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_805_904_Closed_Text.style.display='none'; Codehighlighter1_805_904_Open_Image.style.display='inline'; Codehighlighter1_805_904_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_805_904_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_805_904_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(flg[i]</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)printf(</span><span style="color: #000000">"</span><span style="color: #000000">in\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">out\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">FINISH\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&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 align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span></div><br /><br /></div></pre></div></div><img src ="http://www.cppblog.com/codepeng/aggbug/154443.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/codepeng/" target="_blank">acpeng</a> 2011-08-26 18:04 <a href="http://www.cppblog.com/codepeng/archive/2011/08/26/154443.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ZOJ 1325，HDOJ 1318--Palindromes</title><link>http://www.cppblog.com/codepeng/archive/2011/08/24/154210.html</link><dc:creator>acpeng</dc:creator><author>acpeng</author><pubDate>Wed, 24 Aug 2011 05:20:00 GMT</pubDate><guid>http://www.cppblog.com/codepeng/archive/2011/08/24/154210.html</guid><wfw:comment>http://www.cppblog.com/codepeng/comments/154210.html</wfw:comment><comments>http://www.cppblog.com/codepeng/archive/2011/08/24/154210.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/codepeng/comments/commentRss/154210.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/codepeng/services/trackbacks/154210.html</trackback:ping><description><![CDATA[<div>出自ZOJ_1325：<a href="http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=325">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=325</a><br />主要技巧：设置两个全局的字符串常量，分别表示A~Z的reverse字符和1~9的reverse字符，不存在reverse的可以用任一个invalid characters代替，本代码用@代替，写两个函数分别进行palindrome string和mirrored string的判断。
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">stdio.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">string</span><span style="color: #000000">.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;glo_str[</span><span style="color: #000000">27</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">A@@@3@@HIL@JM@O@@@2TUVWXY5</span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;glo_num[</span><span style="color: #000000">10</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">1SE@Z@@8@</span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;Is_Palindrome(</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">str)</span><span style="color: #008000">//</span><span style="color: #008000">return&nbsp;1:It&nbsp;is&nbsp;a&nbsp;Palindrome&nbsp;string,or&nbsp;else.</span><span style="color: #008000"><br /><img id="Codehighlighter1_188_287_Open_Image" onclick="this.style.display='none'; Codehighlighter1_188_287_Open_Text.style.display='none'; Codehighlighter1_188_287_Closed_Image.style.display='inline'; Codehighlighter1_188_287_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_188_287_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_188_287_Closed_Text.style.display='none'; Codehighlighter1_188_287_Open_Image.style.display='inline'; Codehighlighter1_188_287_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_188_287_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_188_287_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i,j</span><span style="color: #000000">=</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">)strlen(str)</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i</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">j;i</span><span style="color: #000000">++</span><span style="color: #000000">,j</span><span style="color: #000000">--</span><span style="color: #000000">)<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(str[i]</span><span style="color: #000000">!=</span><span style="color: #000000">str[j])<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;Is_mirrored(</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">str)</span><span style="color: #008000">//</span><span style="color: #008000">return&nbsp;1:It&nbsp;is&nbsp;a&nbsp;mirrored&nbsp;string,or&nbsp;else.</span><span style="color: #008000"><br /><img id="Codehighlighter1_359_582_Open_Image" onclick="this.style.display='none'; Codehighlighter1_359_582_Open_Text.style.display='none'; Codehighlighter1_359_582_Closed_Image.style.display='inline'; Codehighlighter1_359_582_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_359_582_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_359_582_Closed_Text.style.display='none'; Codehighlighter1_359_582_Open_Image.style.display='inline'; Codehighlighter1_359_582_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_359_582_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_359_582_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i,j</span><span style="color: #000000">=</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">)strlen(str)</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i</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">j;i</span><span style="color: #000000">++</span><span style="color: #000000">,j</span><span style="color: #000000">--</span><span style="color: #000000">)<br /><img id="Codehighlighter1_414_569_Open_Image" onclick="this.style.display='none'; Codehighlighter1_414_569_Open_Text.style.display='none'; Codehighlighter1_414_569_Closed_Image.style.display='inline'; Codehighlighter1_414_569_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_414_569_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_414_569_Closed_Text.style.display='none'; Codehighlighter1_414_569_Open_Image.style.display='inline'; Codehighlighter1_414_569_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_414_569_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_414_569_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(str[i]</span><span style="color: #000000">&gt;=</span><span style="color: #000000">'</span><span style="color: #000000">1</span><span style="color: #000000">'</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">str[i]</span><span style="color: #000000">&lt;=</span><span style="color: #000000">'</span><span style="color: #000000">9</span><span style="color: #000000">'</span><span style="color: #000000">)<br /><img id="Codehighlighter1_449_502_Open_Image" onclick="this.style.display='none'; Codehighlighter1_449_502_Open_Text.style.display='none'; Codehighlighter1_449_502_Closed_Image.style.display='inline'; Codehighlighter1_449_502_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_449_502_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_449_502_Closed_Text.style.display='none'; Codehighlighter1_449_502_Open_Image.style.display='inline'; Codehighlighter1_449_502_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_449_502_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_449_502_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(glo_num[str[i]</span><span style="color: #000000">-</span><span style="color: #000000">'</span><span style="color: #000000">1</span><span style="color: #000000">'</span><span style="color: #000000">]</span><span style="color: #000000">!=</span><span style="color: #000000">str[j])<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /><img id="Codehighlighter1_513_566_Open_Image" onclick="this.style.display='none'; Codehighlighter1_513_566_Open_Text.style.display='none'; Codehighlighter1_513_566_Closed_Image.style.display='inline'; Codehighlighter1_513_566_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_513_566_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_513_566_Closed_Text.style.display='none'; Codehighlighter1_513_566_Open_Image.style.display='inline'; Codehighlighter1_513_566_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_513_566_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_513_566_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(glo_str[str[i]</span><span style="color: #000000">-</span><span style="color: #000000">'</span><span style="color: #000000">A</span><span style="color: #000000">'</span><span style="color: #000000">]</span><span style="color: #000000">!=</span><span style="color: #000000">str[j])<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_595_986_Open_Image" onclick="this.style.display='none'; Codehighlighter1_595_986_Open_Text.style.display='none'; Codehighlighter1_595_986_Closed_Image.style.display='inline'; Codehighlighter1_595_986_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_595_986_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_595_986_Closed_Text.style.display='none'; Codehighlighter1_595_986_Open_Image.style.display='inline'; Codehighlighter1_595_986_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_595_986_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_595_986_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;str[</span><span style="color: #000000">30</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">"</span><span style="color: #000000">\0</span><span style="color: #000000">"</span><span style="color: #000000">;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a,b;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%s</span><span style="color: #000000">"</span><span style="color: #000000">,str)</span><span style="color: #000000">!=</span><span style="color: #000000">EOF)<br /><img id="Codehighlighter1_659_970_Open_Image" onclick="this.style.display='none'; Codehighlighter1_659_970_Open_Text.style.display='none'; Codehighlighter1_659_970_Closed_Image.style.display='inline'; Codehighlighter1_659_970_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_659_970_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_659_970_Closed_Text.style.display='none'; Codehighlighter1_659_970_Open_Image.style.display='inline'; Codehighlighter1_659_970_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_659_970_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_659_970_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%s&nbsp;--&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">,str);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a</span><span style="color: #000000">=</span><span style="color: #000000">Is_Palindrome(str);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b</span><span style="color: #000000">=</span><span style="color: #000000">Is_mirrored(str);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(a</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;b</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)printf(</span><span style="color: #000000">"</span><span style="color: #000000">is&nbsp;not&nbsp;a&nbsp;palindrome.\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(a</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;b</span><span style="color: #000000">==</span><span style="color: #000000">1</span><span style="color: #000000">)printf(</span><span style="color: #000000">"</span><span style="color: #000000">is&nbsp;a&nbsp;mirrored&nbsp;string.\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(a</span><span style="color: #000000">==</span><span style="color: #000000">1</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;b</span><span style="color: #000000">==</span><span style="color: #000000">0</span><span style="color: #000000">)printf(</span><span style="color: #000000">"</span><span style="color: #000000">is&nbsp;a&nbsp;regular&nbsp;palindrome.\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">is&nbsp;a&nbsp;mirrored&nbsp;palindrome.\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&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 align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span></div><br /></div> <img src ="http://www.cppblog.com/codepeng/aggbug/154210.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/codepeng/" target="_blank">acpeng</a> 2011-08-24 13:20 <a href="http://www.cppblog.com/codepeng/archive/2011/08/24/154210.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ZOJ  1828   Fibonacci Numbers</title><link>http://www.cppblog.com/codepeng/archive/2011/05/22/146922.html</link><dc:creator>acpeng</dc:creator><author>acpeng</author><pubDate>Sun, 22 May 2011 05:56:00 GMT</pubDate><guid>http://www.cppblog.com/codepeng/archive/2011/05/22/146922.html</guid><wfw:comment>http://www.cppblog.com/codepeng/comments/146922.html</wfw:comment><comments>http://www.cppblog.com/codepeng/archive/2011/05/22/146922.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/codepeng/comments/commentRss/146922.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/codepeng/services/trackbacks/146922.html</trackback:ping><description><![CDATA[<div>OJ地址：<a title="http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1828" href="http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1828">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1828</a><br />f(1) = 1, f(2) = 1, f(n &gt; 2) = f(n - 1) + f(n - 2)。<br />输入n，计算f(n)。f(n)位数小于1000。<br /><br /><strong>Sample Input</strong> 
<p>100</p>
<p><br /><strong>Sample Output</strong></p>
<p>354224848179261915075</p><br />基本思路，字符串方式模拟计算过程。简单题。 
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;1</span>&nbsp;<span style="color: #008000">/*</span><span style="color: #008000"><br /></span><span style="color: #008080">&nbsp;2</span>&nbsp;<span style="color: #008000">计算Fibonacci数列第&nbsp;n&nbsp;项<br /></span><span style="color: #008080">&nbsp;3</span>&nbsp;<span style="color: #008000"></span><span style="color: #008000; text-decoration: underline">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1828</span><span style="color: #008000"><br /></span><span style="color: #008080">&nbsp;4</span>&nbsp;<span style="color: #008000"></span><span style="color: #008000">*/</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;5</span>&nbsp;<span style="color: #000000">#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">stdio.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;6</span>&nbsp;<span style="color: #000000">#include</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">string</span><span style="color: #000000">.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;7</span>&nbsp;<span style="color: #000000"></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;addstr(</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">str1,</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">str2,</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">str3)<br /></span><span style="color: #008080">&nbsp;8</span>&nbsp;<span style="color: #000000">{<br /></span><span style="color: #008080">&nbsp;9</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;lgth1,lgth2,c,tmp,i,j,k;<br /></span><span style="color: #008080">10</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;add1num,add2num;<br /></span><span style="color: #008080">11</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;lgth1</span><span style="color: #000000">=</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">)strlen(str1);lgth2</span><span style="color: #000000">=</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">)strlen(str2);<br /></span><span style="color: #008080">12</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;k</span><span style="color: #000000">=</span><span style="color: #000000">lgth1</span><span style="color: #000000">&gt;</span><span style="color: #000000">lgth2</span><span style="color: #000000">?</span><span style="color: #000000">lgth1:lgth2;<br /></span><span style="color: #008080">13</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;str3[k</span><span style="color: #000000">+</span><span style="color: #000000">1</span><span style="color: #000000">]</span><span style="color: #000000">=</span><span style="color: #000000">'</span><span style="color: #000000">\0</span><span style="color: #000000">'</span><span style="color: #000000">;<br /></span><span style="color: #008080">14</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;j</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">15</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(</span><span style="color: #000000">*</span><span style="color: #000000">(str1</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">\0</span><span style="color: #000000">'</span><span style="color: #000000">)i</span><span style="color: #000000">++</span><span style="color: #000000">;i</span><span style="color: #000000">--</span><span style="color: #000000">;<br /></span><span style="color: #008080">16</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(</span><span style="color: #000000">*</span><span style="color: #000000">(str2</span><span style="color: #000000">+</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">'</span><span style="color: #000000">)j</span><span style="color: #000000">++</span><span style="color: #000000">;j</span><span style="color: #000000">--</span><span style="color: #000000">;<br /></span><span style="color: #008080">17</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;c</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">18</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(;i</span><span style="color: #000000">&gt;=</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;j</span><span style="color: #000000">&gt;=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">--</span><span style="color: #000000">,j</span><span style="color: #000000">--</span><span style="color: #000000">,k</span><span style="color: #000000">--</span><span style="color: #000000">)<br /></span><span style="color: #008080">19</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;{<br /></span><span style="color: #008080">20</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(j</span><span style="color: #000000">&lt;</span><span style="color: #000000">0</span><span style="color: #000000">)add2num</span><span style="color: #000000">=</span><span style="color: #000000">'</span><span style="color: #000000">0</span><span style="color: #000000">'</span><span style="color: #000000">;<br /></span><span style="color: #008080">21</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;add2num</span><span style="color: #000000">=*</span><span style="color: #000000">(str2</span><span style="color: #000000">+</span><span style="color: #000000">j);<br /></span><span style="color: #008080">22</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(i</span><span style="color: #000000">&lt;</span><span style="color: #000000">0</span><span style="color: #000000">)add1num</span><span style="color: #000000">=</span><span style="color: #000000">'</span><span style="color: #000000">0</span><span style="color: #000000">'</span><span style="color: #000000">;<br /></span><span style="color: #008080">23</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;add1num</span><span style="color: #000000">=*</span><span style="color: #000000">(str1</span><span style="color: #000000">+</span><span style="color: #000000">i);<br /></span><span style="color: #008080">24</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp</span><span style="color: #000000">=</span><span style="color: #000000">add1num</span><span style="color: #000000">-</span><span style="color: #000000">'</span><span style="color: #000000">0</span><span style="color: #000000">'</span><span style="color: #000000">+</span><span style="color: #000000">add2num</span><span style="color: #000000">-</span><span style="color: #000000">'</span><span style="color: #000000">0</span><span style="color: #000000">'</span><span style="color: #000000">+</span><span style="color: #000000">c;<br /></span><span style="color: #008080">25</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">(str3</span><span style="color: #000000">+</span><span style="color: #000000">k)</span><span style="color: #000000">=</span><span style="color: #000000">tmp</span><span style="color: #000000">%</span><span style="color: #000000">10</span><span style="color: #000000">+</span><span style="color: #000000">'</span><span style="color: #000000">0</span><span style="color: #000000">'</span><span style="color: #000000">;<br /></span><span style="color: #008080">26</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c</span><span style="color: #000000">=</span><span style="color: #000000">tmp</span><span style="color: #000000">/</span><span style="color: #000000">10</span><span style="color: #000000">;<br /></span><span style="color: #008080">27</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #008080">28</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(c</span><span style="color: #000000">!=</span><span style="color: #000000">0</span><span style="color: #000000">)<br /></span><span style="color: #008080">29</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">(str3</span><span style="color: #000000">+</span><span style="color: #000000">k)</span><span style="color: #000000">=</span><span style="color: #000000">c</span><span style="color: #000000">+</span><span style="color: #000000">'</span><span style="color: #000000">0</span><span style="color: #000000">'</span><span style="color: #000000">;<br /></span><span style="color: #008080">30</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /></span><span style="color: #008080">31</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;{<br /></span><span style="color: #008080">32</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;</span><span style="color: #000000">*</span><span style="color: #000000">(str3</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">)</span><span style="color: #000000">!=</span><span style="color: #000000">'</span><span style="color: #000000">\0</span><span style="color: #000000">'</span><span style="color: #000000">;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">33</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">(str3</span><span style="color: #000000">+</span><span style="color: #000000">i)</span><span style="color: #000000">=*</span><span style="color: #000000">(str3</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 /></span><span style="color: #008080">34</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">(str3</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">\0</span><span style="color: #000000">'</span><span style="color: #000000">;<br /></span><span style="color: #008080">35</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #008080">36</span>&nbsp;<span style="color: #000000">}<br /></span><span style="color: #008080">37</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">38</span>&nbsp;<span style="color: #000000"></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /></span><span style="color: #008080">39</span>&nbsp;<span style="color: #000000">{<br /></span><span style="color: #008080">40</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n,j;<br /></span><span style="color: #008080">41</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;str1[</span><span style="color: #000000">1003</span><span style="color: #000000">],str2[</span><span style="color: #000000">1003</span><span style="color: #000000">],Fibo[</span><span style="color: #000000">1003</span><span style="color: #000000">];<br /></span><span style="color: #008080">42</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">&amp;</span><span style="color: #000000">n)</span><span style="color: #000000">!=</span><span style="color: #000000">EOF)<br /></span><span style="color: #008080">43</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;{<br /></span><span style="color: #008080">44</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(str1,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #000000">1003</span><span style="color: #000000">);<br /></span><span style="color: #008080">45</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(str2,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #000000">1003</span><span style="color: #000000">);<br /></span><span style="color: #008080">46</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(Fibo,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #000000">1003</span><span style="color: #000000">);<br /></span><span style="color: #008080">47</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcpy(str2,</span><span style="color: #000000">"</span><span style="color: #000000">1</span><span style="color: #000000">"</span><span style="color: #000000">);<br /></span><span style="color: #008080">48</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(j</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">;j</span><span style="color: #000000">&lt;=</span><span style="color: #000000">n;j</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">49</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /></span><span style="color: #008080">50</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(str1,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #000000">1003</span><span style="color: #000000">);<br /></span><span style="color: #008080">51</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcpy(str1,str2);<br /></span><span style="color: #008080">52</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(str2,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #000000">1003</span><span style="color: #000000">);<br /></span><span style="color: #008080">53</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcpy(str2,Fibo);<br /></span><span style="color: #008080">54</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;addstr(str1,str2,Fibo);<br /></span><span style="color: #008080">55</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #008080">56</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%s\n</span><span style="color: #000000">"</span><span style="color: #000000">,Fibo);<br /></span><span style="color: #008080">57</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #008080">58</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&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 /></span><span style="color: #008080">59</span>&nbsp;<span style="color: #000000">}</span></div><br /><br /></div><img src ="http://www.cppblog.com/codepeng/aggbug/146922.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/codepeng/" target="_blank">acpeng</a> 2011-05-22 13:56 <a href="http://www.cppblog.com/codepeng/archive/2011/05/22/146922.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ZOJ  1170--String Matching</title><link>http://www.cppblog.com/codepeng/archive/2011/05/12/146239.html</link><dc:creator>acpeng</dc:creator><author>acpeng</author><pubDate>Thu, 12 May 2011 02:23:00 GMT</pubDate><guid>http://www.cppblog.com/codepeng/archive/2011/05/12/146239.html</guid><wfw:comment>http://www.cppblog.com/codepeng/comments/146239.html</wfw:comment><comments>http://www.cppblog.com/codepeng/archive/2011/05/12/146239.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/codepeng/comments/commentRss/146239.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/codepeng/services/trackbacks/146239.html</trackback:ping><description><![CDATA[<p style="FONT-FAMILY: courier new">OJ地址： <a title=http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=170 href="http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=170">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=170</a><br><br>It's easy to tell if two words are identical - just check the letters. But how do you tell if two words are almost identical? And how close is "almost"?<br>There are lots of techniques for approximate word matching. One is to determine the best substring match, which is the number of common letters when the words are compared letter-byletter.<br>The key to this approach is that the words can overlap in any way. For example, consider the words CAPILLARY and MARSUPIAL. One way to compare them is to overlay them: </p>
<p style="FONT-FAMILY: courier new">CAPILLARY<br>MARSUPIAL<br><br>There is only one common letter (A). Better is the following overlay:<br><br>CAPILLARY<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MARSUPIAL<br><br>with two common letters (A and R), but the best is:<br><br>&nbsp;&nbsp;&nbsp;CAPILLARY<br>MARSUPIAL </p>
<p style="FONT-FAMILY: courier new">Which has three common letters (P, I and L).<br><br>The approximation measure appx(word1, word2) for two words is given by:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;common letters * 2<br>-----------------------------<br>length(word1) + length(word2)<br><br>Thus, for this example, appx(CAPILLARY, MARSUPIAL) = 6 / (9 + 9) = 1/3. Obviously, for any word W appx(W, W) = 1, which is a nice property, while words with no common letters have an appx value of 0.<br><strong>Input:</strong><br>The input for your program will be a series of words, two per line, until the end-of-file flag of -1.<br>Using the above technique, you are to calculate appx() for the pair of words on the line and print the result. For example:<br><br><span style="COLOR: #0000ff">CAR CART<br>TURKEY CHICKEN<br>MONEY POVERTY<br>ROUGH PESKY<br>A A<br>-1<br></span><br>The words will all be uppercase.<br><strong>Output:</strong><br>Print the value for appx() for each pair as a reduced fraction, like this:<br><br><span style="COLOR: #0000ff">appx(CAR,CART) = 6/7<br>appx(TURKEY,CHICKEN) = 4/13<br>appx(MONEY,POVERTY) = 1/3<br>appx(ROUGH,PESKY) = 0<br>appx(A,A) = 1<br><br></span>Fractions reducing to zero or one should have no denominator<br><br>代码：<br></p>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">&nbsp;1</span>&nbsp;<span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">&nbsp;2</span>&nbsp;<span style="COLOR: #008000"></span><span style="COLOR: #008000; TEXT-DECORATION: underline">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1170</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">&nbsp;3</span>&nbsp;<span style="COLOR: #008000">2011.5.12<br></span><span style="COLOR: #008080">&nbsp;4</span>&nbsp;<span style="COLOR: #008000"></span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;5</span>&nbsp;<span style="COLOR: #000000">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">stdio.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;6</span>&nbsp;<span style="COLOR: #000000">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;7</span>&nbsp;<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br></span><span style="COLOR: #008080">&nbsp;8</span>&nbsp;<span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;9</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,j,k,lgth1,lgth2,num,max,tmp1,tmp2,flg;<br></span><span style="COLOR: #008080">10</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;str1[</span><span style="COLOR: #000000">1000</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\0</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,str2[</span><span style="COLOR: #000000">1000</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\0</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">11</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">12</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="COLOR: #008080">13</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%s</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,str1);<br></span><span style="COLOR: #008080">14</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(strcmp(str1,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">-1</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">15</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%s</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,str2);<br></span><span style="COLOR: #008080">16</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;max</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">17</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lgth1</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">)strlen(str1);<br></span><span style="COLOR: #008080">18</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lgth2</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">)strlen(str2);<br></span><span style="COLOR: #008080">19</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;k</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">lgth1;k</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">20</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="COLOR: #008080">21</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">22</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">k;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">lgth1&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;j</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">lgth2;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">,j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">23</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(str1[i]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">str2[j])num</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">24</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(max</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">num)&nbsp;max</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">num;<br></span><span style="COLOR: #008080">25</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">26</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="COLOR: #008080">27</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">28</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;k</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">lgth2;k</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">29</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="COLOR: #008080">30</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">31</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">k;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">lgth2&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;j</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">lgth1;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">,j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">32</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(str2[i]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">str1[j])num</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">33</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br></span><span style="COLOR: #008080">34</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(max</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">num)&nbsp;max</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">num;<br></span><span style="COLOR: #008080">35</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">36</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="COLOR: #008080">37</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">appx(%s,%s)&nbsp;=&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,str1,str2);<br></span><span style="COLOR: #008080">38</span>&nbsp;<span style="COLOR: #000000"><br></span><span style="COLOR: #008080">39</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">化简分式</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">40</span>&nbsp;<span style="COLOR: #008000"></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(max</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">0\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">41</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(max</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;lgth1</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">lgth2)&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">1\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">42</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">43</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="COLOR: #008080">44</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp1</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">max</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;tmp2</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">lgth1</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">lgth2;<br></span><span style="COLOR: #008080">45</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">46</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="COLOR: #008080">47</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flg</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">48</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000">tmp1;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">49</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="COLOR: #008080">50</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(tmp1</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;tmp2</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">51</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="COLOR: #008080">52</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp1</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">tmp1</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">i;&nbsp;tmp2</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">tmp2</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">i;<br></span><span style="COLOR: #008080">53</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flg</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">54</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">55</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="COLOR: #008080">56</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="COLOR: #008080">57</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(flg</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)&nbsp;</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">58</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="COLOR: #008080">59</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d/%d\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,tmp1,tmp2);<br></span><span style="COLOR: #008080">60</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="COLOR: #008080">61</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(str1,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">(str1));<br></span><span style="COLOR: #008080">62</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(str2,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">(str2));<br></span><span style="COLOR: #008080">63</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="COLOR: #008080">64</span>&nbsp;<span style="COLOR: #000000">&nbsp;&nbsp;&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></span><span style="COLOR: #008080">65</span>&nbsp;<span style="COLOR: #000000">}</span></div>
<img src ="http://www.cppblog.com/codepeng/aggbug/146239.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/codepeng/" target="_blank">acpeng</a> 2011-05-12 10:23 <a href="http://www.cppblog.com/codepeng/archive/2011/05/12/146239.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Delete Number——百思不得其解</title><link>http://www.cppblog.com/codepeng/archive/2011/05/11/146221.html</link><dc:creator>acpeng</dc:creator><author>acpeng</author><pubDate>Wed, 11 May 2011 15:38:00 GMT</pubDate><guid>http://www.cppblog.com/codepeng/archive/2011/05/11/146221.html</guid><wfw:comment>http://www.cppblog.com/codepeng/comments/146221.html</wfw:comment><comments>http://www.cppblog.com/codepeng/archive/2011/05/11/146221.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/codepeng/comments/commentRss/146221.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/codepeng/services/trackbacks/146221.html</trackback:ping><description><![CDATA[昨天逛一论坛，遇到一道<span style="FONT-FAMILY: courier new">acm</span>题，地址是<a title=http://acmpj.zstu.edu.cn/JudgeOnline/showproblem?problem_id=2511 href="http://acmpj.zstu.edu.cn/JudgeOnline/showproblem?problem_id=2511"><span style="FONT-FAMILY: Verdana">http://acmpj.zstu.edu.cn/JudgeOnline/showproblem?problem_id=2511</span></a><br>大致意思是从一个有 <span style="FONT-FAMILY: courier new">n </span>位的整数中删除 <span style="FONT-FAMILY: courier new">k </span>位，使剩下的数字按原来的顺序组成的数最小。<br>我的代码总是<span style="FONT-FAMILY: Verdana">WA</span>，不知有没有大牛路过，指点一二，在此谢。<br>我的思路是这样：<br>步骤一：在第 1&nbsp; 位到第 <span style="FONT-FAMILY: Verdana">k+1 </span>位之间（含第 <span style="FONT-FAMILY: Verdana">k+1</span> 位）找出最小的数字，记录这个数字所在的位数p；<br>步骤二：再从第 <span style="FONT-FAMILY: Verdana">p </span>位到第 <span style="FONT-FAMILY: Verdana">k+2 </span>位之间找出最小的数字，再记录此数所在的位数p；<br>后面重复 <span style="FONT-FAMILY: courier new">n-k </span>次前面的操作，这样按顺序输出每一次操作得到的最小数字即可。当然输出时注意去掉起始的若干个0。<br>下面是代码<br>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #000000">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">stdio.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;a[</span><span style="COLOR: #000000">1005</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\0</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,rslt[</span><span style="COLOR: #000000">1005</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\0</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;T,k,n,i,j,lp;<br>&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">T);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(T</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">k);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%s</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,a);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;n</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">)strlen(a);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(k</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">n)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">0\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">continue</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lp</span><span style="COLOR: #000000">=-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;j</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">n</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">k;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lp</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rslt[j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">a[lp];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">lp;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">k</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">j</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(rslt[j]&nbsp;</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;a[i])<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rslt[j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">a[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lp</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">(rslt</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">0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">(rslt</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">\0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%s\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,rslt</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">i);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(a,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">(a));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(rslt,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">(rslt));<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&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>}<br></span></div>
<img src ="http://www.cppblog.com/codepeng/aggbug/146221.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/codepeng/" target="_blank">acpeng</a> 2011-05-11 23:38 <a href="http://www.cppblog.com/codepeng/archive/2011/05/11/146221.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>X倍数问题</title><link>http://www.cppblog.com/codepeng/archive/2011/05/02/145491.html</link><dc:creator>acpeng</dc:creator><author>acpeng</author><pubDate>Mon, 02 May 2011 06:48:00 GMT</pubDate><guid>http://www.cppblog.com/codepeng/archive/2011/05/02/145491.html</guid><wfw:comment>http://www.cppblog.com/codepeng/comments/145491.html</wfw:comment><comments>http://www.cppblog.com/codepeng/archive/2011/05/02/145491.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/codepeng/comments/commentRss/145491.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/codepeng/services/trackbacks/145491.html</trackback:ping><description><![CDATA[<p style="FONT-FAMILY: Verdana" align=left>OJ地址链接：<a title=http://acm.cugb.edu.cn/JudgeOnline/showproblem?problem_id=1022 href="http://acm.cugb.edu.cn/JudgeOnline/showproblem?problem_id=1022">http://acm.cugb.edu.cn/JudgeOnline/showproblem?problem_id=1022</a><br>Description </p>
<p style="FONT-FAMILY: Verdana">若一个整数Y的个位数为X，将X移到最高位得到的恰好是Y的X倍，称Y为一个X倍数。例如，0是一个0倍数，1是一个1倍数。</p>
<p style="FONT-FAMILY: Verdana">Input</p>
<p style="FONT-FAMILY: Verdana">无</p>
<p style="FONT-FAMILY: Verdana">Output</p>
<p style="FONT-FAMILY: Verdana">请依次输出最小的0倍数、1倍数、2倍数、&#8230;&#8230;9倍数。每个X倍数输出一行。</p>
<p style="FONT-FAMILY: Verdana"><strong>Sample Input </strong></p>
<p style="FONT-FAMILY: Verdana">无</p>
<p style="FONT-FAMILY: Verdana"><strong>Sample Output </strong></p>
<p style="FONT-FAMILY: Verdana">0</p>
<p style="FONT-FAMILY: Verdana">1</p>
<p style="FONT-FAMILY: Verdana">&#8230;&#8230;</p>
<p style="FONT-FAMILY: Verdana">&#8230;&#8230;</p>
<p style="FONT-FAMILY: Verdana">&#8230;&#8230;</p>
<p style="FONT-FAMILY: Verdana">Hint </p>
<p style="FONT-FAMILY: Verdana">即使是最小的X倍数也可能是一个非常大的整数，甚至远远超出int所能表达的范围。<br>&nbsp;<br>对于X倍数，设定一个数组（事实上应该是字符串，节省空间），第0位赋予初始值k，k=2,3,&#8230;&#8230;9,依次与k相乘得到上一位，即可。注意循环跳出的条件。<br>代码:<br></p>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #000000">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">stdio.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;str[</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\0</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,c,j,k;<br>&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">0\n1\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;k</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">;k</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">k</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;c</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str[i</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">((str[i]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">k</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">c)</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">((str[i]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">k</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">c)</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">((str[i]</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">k</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">k&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;c</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br>&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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i;j</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;j</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%c</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,str[j]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(str,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">(str));<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&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>}</span></div>
<img src ="http://www.cppblog.com/codepeng/aggbug/145491.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/codepeng/" target="_blank">acpeng</a> 2011-05-02 14:48 <a href="http://www.cppblog.com/codepeng/archive/2011/05/02/145491.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ZOJ Monthly, May 2011 .Problem B</title><link>http://www.cppblog.com/codepeng/archive/2011/05/01/145463.html</link><dc:creator>acpeng</dc:creator><author>acpeng</author><pubDate>Sun, 01 May 2011 09:21:00 GMT</pubDate><guid>http://www.cppblog.com/codepeng/archive/2011/05/01/145463.html</guid><wfw:comment>http://www.cppblog.com/codepeng/comments/145463.html</wfw:comment><comments>http://www.cppblog.com/codepeng/archive/2011/05/01/145463.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/codepeng/comments/commentRss/145463.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/codepeng/services/trackbacks/145463.html</trackback:ping><description><![CDATA[ZOJ Monthly, May 2011 .Problem B:Roman Order:<a title=http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3501 href="http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3501">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3501</a>
<p style="FONT-FAMILY: Verdana"><br>Roman numerals are based on seven symbols: I = 1, V = 5, X = 10, L = 50, C = 100, D = 500 and M = 1000. </p>
<p style="FONT-FAMILY: Verdana">Symbols are iterated to produce multiples of the decimal (1, 10, 100, 1,000) values, with V, L, D substituted for a multiple of five, and the iteration continuing: I "1", II "2", III "3", V "5", VI "6", VII "7", etc., and the same for other bases: X "10", XX "20", XXX "30", L "50", LXXX "80"; CC "200", DCC "700", etc. At the fourth iteration, a subtractive principle is employed, with the base placed before the higher base: IV for "4", IX for "9", XL for "40", XC for "90", CD for "400", CM for "900". </p>
<p style="FONT-FAMILY: Verdana">The basic multiples of Roman numerals thus follow a pattern:
<center>
<table id=the-tab>
    <tbody>
        <tr>
            <th></th>
            <th>&#215;1</th>
            <th>&#215;2</th>
            <th>&#215;3</th>
            <th>&#215;4</th>
            <th>&#215;5</th>
            <th>&#215;6</th>
            <th>&#215;7</th>
            <th>&#215;8</th>
            <th>&#215;9</th>
        </tr>
        <tr>
            <th>Ones</th>
            <td style="FONT-FAMILY: Verdana">I</td>
            <td style="FONT-FAMILY: Verdana">II</td>
            <td style="FONT-FAMILY: Verdana">III</td>
            <td style="FONT-FAMILY: Verdana">IV</td>
            <td style="FONT-FAMILY: Verdana">V</td>
            <td style="FONT-FAMILY: Verdana">VI</td>
            <td style="FONT-FAMILY: Verdana">VII</td>
            <td style="FONT-FAMILY: Verdana">VIII</td>
            <td style="FONT-FAMILY: Verdana">IX</td>
        </tr>
        <tr>
            <th>Tens</th>
            <td style="FONT-FAMILY: Verdana">X</td>
            <td style="FONT-FAMILY: Verdana">XX</td>
            <td style="FONT-FAMILY: Verdana">XXX</td>
            <td style="FONT-FAMILY: Verdana">XL</td>
            <td style="FONT-FAMILY: Verdana">L</td>
            <td style="FONT-FAMILY: Verdana">LX</td>
            <td style="FONT-FAMILY: Verdana">LXX</td>
            <td style="FONT-FAMILY: Verdana">LXXX</td>
            <td style="FONT-FAMILY: Verdana">XC</td>
        </tr>
        <tr>
            <th>Hundreds</th>
            <td style="FONT-FAMILY: Verdana">C</td>
            <td style="FONT-FAMILY: Verdana">CC</td>
            <td style="FONT-FAMILY: Verdana">CCC</td>
            <td style="FONT-FAMILY: Verdana">CD</td>
            <td style="FONT-FAMILY: Verdana">D</td>
            <td style="FONT-FAMILY: Verdana">DC</td>
            <td style="FONT-FAMILY: Verdana">DCC</td>
            <td style="FONT-FAMILY: Verdana">DCCC</td>
            <td style="FONT-FAMILY: Verdana">CM</td>
        </tr>
        <tr>
            <th>Thousands</th>
            <td style="FONT-FAMILY: Verdana">M</td>
            <td style="FONT-FAMILY: Verdana">MM</td>
            <td style="FONT-FAMILY: Verdana">MMM</td>
            <td style="FONT-FAMILY: Verdana"></td>
            <td style="FONT-FAMILY: Verdana"></td>
            <td style="FONT-FAMILY: Verdana"></td>
            <td style="FONT-FAMILY: Verdana"></td>
            <td style="FONT-FAMILY: Verdana"></td>
            <td style="FONT-FAMILY: Verdana"></td>
        </tr>
    </tbody>
</table>
</center>
<p style="FONT-FAMILY: Verdana"></p>
<p style="FONT-FAMILY: Verdana">A practical way to write a Roman number is to consider the modern Arabic numeral system, and separately convert the thousands, hundreds, tens, and ones as given in the chart above. So, for instance, 1234 may be thought of as "one thousand and two hundreds and three tens and four", obtaining M (one thousand) + CC (two hundreds) + XXX (thirty) + IV (four), for MCCXXXIV. Thus eleven is XI (ten and one), 29 is XXIX (twenty and nine), and 2011 is MMXI (two thousand and ten and one). Note that the subtractive principle is not extended beyond the chart: for example, IL is not used for 49, rather this should be written as forty (XL) and nine (IX), or XLIX. </p>
<p style="FONT-FAMILY: Verdana">Given a list of numbers, you are to rearrange them so that if we write them as Roman numbers, they are in lexicographical order. </p>
<h4>Input</h4>
<p style="FONT-FAMILY: Verdana">There are multiple test cases. The first line of input is an integer T ≈ 100 indicating the number of test cases. </p>
<p style="FONT-FAMILY: Verdana">Each test case starts with an integer 1 &#8804; n &#8804; 10000. Then n numbers 0 &lt; ai &lt; 4000. </p>
<h4>Output</h4>
<p style="FONT-FAMILY: Verdana">For each test case, output the n numbers in specified order. </p>
<h4>Sample Input</h4>
<pre>3
3
1 2 3
7
1 5 10 50 100 500 1000
11
4 5 6 7 8 9 10 11 12 13 14
</pre>
<h4>Sample Output</h4>
<pre>1 2 3
100 500 1 50 1000 5 10
4 9 5 6 7 8 10 11 12 13 14</pre>
<pre>代码：</pre>
<pre>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080">&nbsp;1</span><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">stdio.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;2</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;3</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">algorithm</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;4</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></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></span><span style="COLOR: #008080">&nbsp;5</span><span style="COLOR: #000000"><img id=Codehighlighter1_102_149_Open_Image onclick="this.style.display='none'; Codehighlighter1_102_149_Open_Text.style.display='none'; Codehighlighter1_102_149_Closed_Image.style.display='inline'; Codehighlighter1_102_149_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_102_149_Closed_Image onclick="this.style.display='none'; Codehighlighter1_102_149_Closed_Text.style.display='none'; Codehighlighter1_102_149_Open_Image.style.display='inline'; Codehighlighter1_102_149_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;strHundreds[</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_102_149_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_102_149_Open_Text><span style="COLOR: #000000">{</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">C</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">CC</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">CCC</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">CD</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">D</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">DC</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">DCC</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">DCCC</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">CM</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">}</span></span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">&nbsp;6</span><span style="COLOR: #000000"><img id=Codehighlighter1_172_219_Open_Image onclick="this.style.display='none'; Codehighlighter1_172_219_Open_Text.style.display='none'; Codehighlighter1_172_219_Closed_Image.style.display='inline'; Codehighlighter1_172_219_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_172_219_Closed_Image onclick="this.style.display='none'; Codehighlighter1_172_219_Closed_Text.style.display='none'; Codehighlighter1_172_219_Open_Image.style.display='inline'; Codehighlighter1_172_219_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;strTens[</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_172_219_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_172_219_Open_Text><span style="COLOR: #000000">{</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">X</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">XX</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">XXX</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">XL</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">L</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">LX</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">LXX</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">LXXX</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">XC</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">}</span></span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">&nbsp;7</span><span style="COLOR: #000000"><img id=Codehighlighter1_242_289_Open_Image onclick="this.style.display='none'; Codehighlighter1_242_289_Open_Text.style.display='none'; Codehighlighter1_242_289_Closed_Image.style.display='inline'; Codehighlighter1_242_289_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_242_289_Closed_Image onclick="this.style.display='none'; Codehighlighter1_242_289_Closed_Text.style.display='none'; Codehighlighter1_242_289_Open_Image.style.display='inline'; Codehighlighter1_242_289_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;strOnes[</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_242_289_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_242_289_Open_Text><span style="COLOR: #000000">{</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">"</span><span style="COLOR: #000000">II</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">III</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">IV</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">V</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">VI</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">VII</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">VIII</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">IX</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">}</span></span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">&nbsp;8</span><span style="COLOR: #000000"><img id=Codehighlighter1_316_331_Open_Image onclick="this.style.display='none'; Codehighlighter1_316_331_Open_Text.style.display='none'; Codehighlighter1_316_331_Closed_Image.style.display='inline'; Codehighlighter1_316_331_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_316_331_Closed_Image onclick="this.style.display='none'; Codehighlighter1_316_331_Closed_Text.style.display='none'; Codehighlighter1_316_331_Open_Image.style.display='inline'; Codehighlighter1_316_331_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;strThousands[</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_316_331_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_316_331_Open_Text><span style="COLOR: #000000">{</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">M</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">MM</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">MMM</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">}</span></span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">&nbsp;9</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">typedef&nbsp;</span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000">&nbsp;node<br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img id=Codehighlighter1_354_381_Open_Image onclick="this.style.display='none'; Codehighlighter1_354_381_Open_Text.style.display='none'; Codehighlighter1_354_381_Closed_Image.style.display='inline'; Codehighlighter1_354_381_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_354_381_Closed_Image onclick="this.style.display='none'; Codehighlighter1_354_381_Closed_Text.style.display='none'; Codehighlighter1_354_381_Open_Image.style.display='inline'; Codehighlighter1_354_381_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_354_381_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_354_381_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;str[</span><span style="COLOR: #000000">20</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;flg;<br></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000">NODE;<br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">NODE&nbsp;data[</span><span style="COLOR: #000000">10005</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img id=Codehighlighter1_421_423_Open_Image onclick="this.style.display='none'; Codehighlighter1_421_423_Open_Text.style.display='none'; Codehighlighter1_421_423_Closed_Image.style.display='inline'; Codehighlighter1_421_423_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_421_423_Closed_Image onclick="this.style.display='none'; Codehighlighter1_421_423_Closed_Text.style.display='none'; Codehighlighter1_421_423_Open_Image.style.display='inline'; Codehighlighter1_421_423_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;num[</span><span style="COLOR: #000000">10005</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_421_423_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_421_423_Open_Text><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">}</span></span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;cmp(NODE&nbsp;b,&nbsp;NODE&nbsp;c)<br></span><span style="COLOR: #008080">17</span><span style="COLOR: #000000"><img id=Codehighlighter1_450_509_Open_Image onclick="this.style.display='none'; Codehighlighter1_450_509_Open_Text.style.display='none'; Codehighlighter1_450_509_Closed_Image.style.display='inline'; Codehighlighter1_450_509_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_450_509_Closed_Image onclick="this.style.display='none'; Codehighlighter1_450_509_Closed_Text.style.display='none'; Codehighlighter1_450_509_Open_Image.style.display='inline'; Codehighlighter1_450_509_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_450_509_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_450_509_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">18</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(strcmp(b.str,c.str)</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">19</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">20</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">21</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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></span><span style="COLOR: #008080">22</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">23</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br></span><span style="COLOR: #008080">24</span><span style="COLOR: #000000"><img id=Codehighlighter1_522_1316_Open_Image onclick="this.style.display='none'; Codehighlighter1_522_1316_Open_Text.style.display='none'; Codehighlighter1_522_1316_Closed_Image.style.display='inline'; Codehighlighter1_522_1316_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_522_1316_Closed_Image onclick="this.style.display='none'; Codehighlighter1_522_1316_Closed_Text.style.display='none'; Codehighlighter1_522_1316_Open_Image.style.display='inline'; Codehighlighter1_522_1316_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_522_1316_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_522_1316_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">25</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i,T,n,num_temp_a;<br></span><span style="COLOR: #008080">26</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;tmp[</span><span style="COLOR: #000000">20</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\0</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">27</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">T);<br></span><span style="COLOR: #008080">28</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(T</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">29</span><span style="COLOR: #000000"><img id=Codehighlighter1_598_1303_Open_Image onclick="this.style.display='none'; Codehighlighter1_598_1303_Open_Text.style.display='none'; Codehighlighter1_598_1303_Closed_Image.style.display='inline'; Codehighlighter1_598_1303_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_598_1303_Closed_Image onclick="this.style.display='none'; Codehighlighter1_598_1303_Closed_Text.style.display='none'; Codehighlighter1_598_1303_Open_Image.style.display='inline'; Codehighlighter1_598_1303_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_598_1303_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_598_1303_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">30</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">n);<br></span><span style="COLOR: #008080">31</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">n;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">32</span><span style="COLOR: #000000"><img id=Codehighlighter1_639_1171_Open_Image onclick="this.style.display='none'; Codehighlighter1_639_1171_Open_Text.style.display='none'; Codehighlighter1_639_1171_Closed_Image.style.display='inline'; Codehighlighter1_639_1171_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_639_1171_Closed_Image onclick="this.style.display='none'; Codehighlighter1_639_1171_Closed_Text.style.display='none'; Codehighlighter1_639_1171_Open_Image.style.display='inline'; Codehighlighter1_639_1171_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_639_1171_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_639_1171_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">33</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">num[i]);<br></span><span style="COLOR: #008080">34</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num_temp_a</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">num[i];<br></span><span style="COLOR: #008080">35</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(num_temp_a</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">1000</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">36</span><span style="COLOR: #000000"><img id=Codehighlighter1_716_802_Open_Image onclick="this.style.display='none'; Codehighlighter1_716_802_Open_Text.style.display='none'; Codehighlighter1_716_802_Closed_Image.style.display='inline'; Codehighlighter1_716_802_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_716_802_Closed_Image onclick="this.style.display='none'; Codehighlighter1_716_802_Closed_Text.style.display='none'; Codehighlighter1_716_802_Open_Image.style.display='inline'; Codehighlighter1_716_802_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_716_802_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_716_802_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">37</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(tmp,strThousands[num_temp_a</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">1000</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]);<br></span><span style="COLOR: #008080">38</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num_temp_a</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">num_temp_a</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">1000</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">39</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">40</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(num_temp_a</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">41</span><span style="COLOR: #000000"><img id=Codehighlighter1_832_915_Open_Image onclick="this.style.display='none'; Codehighlighter1_832_915_Open_Text.style.display='none'; Codehighlighter1_832_915_Closed_Image.style.display='inline'; Codehighlighter1_832_915_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_832_915_Closed_Image onclick="this.style.display='none'; Codehighlighter1_832_915_Closed_Text.style.display='none'; Codehighlighter1_832_915_Open_Image.style.display='inline'; Codehighlighter1_832_915_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_832_915_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_832_915_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">42</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(tmp,strHundreds[num_temp_a</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]);<br></span><span style="COLOR: #008080">43</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num_temp_a</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">num_temp_a</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">44</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">45</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(num_temp_a</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">46</span><span style="COLOR: #000000"><img id=Codehighlighter1_944_1021_Open_Image onclick="this.style.display='none'; Codehighlighter1_944_1021_Open_Text.style.display='none'; Codehighlighter1_944_1021_Closed_Image.style.display='inline'; Codehighlighter1_944_1021_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_944_1021_Closed_Image onclick="this.style.display='none'; Codehighlighter1_944_1021_Closed_Text.style.display='none'; Codehighlighter1_944_1021_Open_Image.style.display='inline'; Codehighlighter1_944_1021_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_944_1021_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_944_1021_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">47</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(tmp,strTens[num_temp_a</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]);<br></span><span style="COLOR: #008080">48</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num_temp_a</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">num_temp_a</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">49</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">50</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(num_temp_a</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">51</span><span style="COLOR: #000000"><img id=Codehighlighter1_1047_1091_Open_Image onclick="this.style.display='none'; Codehighlighter1_1047_1091_Open_Text.style.display='none'; Codehighlighter1_1047_1091_Closed_Image.style.display='inline'; Codehighlighter1_1047_1091_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1047_1091_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1047_1091_Closed_Text.style.display='none'; Codehighlighter1_1047_1091_Open_Image.style.display='inline'; Codehighlighter1_1047_1091_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1047_1091_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1047_1091_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">52</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(tmp,strOnes[num_temp_a</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]);<br></span><span style="COLOR: #008080">53</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">54</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcpy(data[i].str,tmp);<br></span><span style="COLOR: #008080">55</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data[i].flg</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">i;<br></span><span style="COLOR: #008080">56</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(tmp,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">(tmp));<br></span><span style="COLOR: #008080">57</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">58</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sort(data,data</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">n,cmp);<br></span><span style="COLOR: #008080">59</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,num[data[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">].flg]);<br></span><span style="COLOR: #008080">60</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</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></span><span style="COLOR: #008080">61</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,num[data[i].flg]);<br></span><span style="COLOR: #008080">62</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">63</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">64</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&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></span><span style="COLOR: #008080">65</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">66</span><span style="COLOR: #000000"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span></div>
</pre>
<img src ="http://www.cppblog.com/codepeng/aggbug/145463.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/codepeng/" target="_blank">acpeng</a> 2011-05-01 17:21 <a href="http://www.cppblog.com/codepeng/archive/2011/05/01/145463.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>apeng版的解题报告</title><link>http://www.cppblog.com/codepeng/archive/2011/05/01/145434.html</link><dc:creator>acpeng</dc:creator><author>acpeng</author><pubDate>Sat, 30 Apr 2011 17:25:00 GMT</pubDate><guid>http://www.cppblog.com/codepeng/archive/2011/05/01/145434.html</guid><wfw:comment>http://www.cppblog.com/codepeng/comments/145434.html</wfw:comment><comments>http://www.cppblog.com/codepeng/archive/2011/05/01/145434.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/codepeng/comments/commentRss/145434.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/codepeng/services/trackbacks/145434.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 貌似现在TLU的程序设计大赛举办的越来越勤了，像我这样一个codefans，怎么说也要来捧捧场，本人抛砖引玉，贴一个非官方的解题报告，仅供娱乐~~本人所贴代码都是在OJ里面通过的，所以请放心阅读~~1：阶乘问题对于一个任意位数的整数n，则n的位数digit=[log(10)(n)]+1;这里log(10)(x)表示以10为底的x的对数，[x]表示不超过实数x的最大整数，这个证明很容易，稍微算一...&nbsp;&nbsp;<a href='http://www.cppblog.com/codepeng/archive/2011/05/01/145434.html'>阅读全文</a><img src ="http://www.cppblog.com/codepeng/aggbug/145434.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/codepeng/" target="_blank">acpeng</a> 2011-05-01 01:25 <a href="http://www.cppblog.com/codepeng/archive/2011/05/01/145434.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>