<p style="margin-bottom:0px; padding-top:0px; padding-bottom:0px; word-break:normal; color:rgb(85,85,85); font-family:'microsoft yahei'; font-size:15px; line-height:35px; text-align:start; background-color:rgb(255,255,255)"> <span style="font-family:SimSun; font-size:18px"><strong>问题链接</strong>:<a href="http://poj.org/problem?id=3749" rel="noopener noreferrer" style="color:rgb(12,137,207)" target="_blank">POJ3749 破译密码</a></span></p>
<p style="margin-bottom:0px; padding-top:0px; padding-bottom:0px; word-break:normal; color:rgb(85,85,85); font-family:'microsoft yahei'; font-size:15px; line-height:35px; text-align:start; background-color:rgb(255,255,255)"> <span style="font-size:18px"><span style="font-family:SimSun"><strong>问题简述</strong>:(略)<br> </span></span></p>
<p style="margin-bottom:0px; padding-top:0px; padding-bottom:0px; word-break:normal; color:rgb(85,85,85); font-family:'microsoft yahei'; font-size:15px; line-height:35px; text-align:start; background-color:rgb(255,255,255)"> <span style="font-size:18px"><span style="font-family:SimSun"><strong>问题分析</strong>:查表法仍然是一种好办法。有些程序员通过观察,找出编码规律,用程序来译码,程序没有通用性,不值得推荐和借鉴。</span></span></p>
<p style="margin-bottom:0px; padding-top:0px; padding-bottom:0px; word-break:normal; color:rgb(85,85,85); font-family:'microsoft yahei'; font-size:15px; line-height:35px; text-align:start; background-color:rgb(255,255,255)"> <span style="font-size:18px"><span style="font-family:SimSun"></span></span></p>
<pre class="sio" name="code" style="color: rgb(85, 85, 85); font-size: 15px; line-height: 35px; background-color: rgb(255, 255, 255);">START
NS BFW, JAJSYX TK NRUTWYFSHJ FWJ YMJ WJXZQY TK YWNANFQ HFZXJX
END
START
N BTZQI WFYMJW GJ KNWXY NS F QNYYQJ NGJWNFS ANQQFLJ YMFS XJHTSI NS WTRJ
END
START
IFSLJW PSTBX KZQQ BJQQ YMFY HFJXFW NX RTWJ IFSLJWTZX YMFS MJ
END
ENDOFINPUT</pre>
<p></p>
<p class="pst" style="margin-bottom:0px; padding-top:0px; padding-bottom:0px; word-break:normal; color:rgb(85,85,85); font-family:'microsoft yahei'; font-size:15px; line-height:35px; text-align:start; background-color:rgb(255,255,255)"> Sample Output</p>
<pre class="sio" name="code" style="color: rgb(85, 85, 85); font-size: 15px; line-height: 35px; background-color: rgb(255, 255, 255);">IN WAR, EVENTS OF IMPORTANCE ARE THE RESULT OF TRIVIAL CAUSES
I WOULD RATHER BE FIRST IN A LITTLE IBERIAN VILLAGE THAN SECOND IN ROME
DANGER KNOWS FULL WELL THAT CAESAR IS MORE DANGEROUS THAN HE</pre>大致思路:
<p style="margin-bottom:0px; padding-top:0px; padding-bottom:0px; word-break:normal; color:rgb(85,85,85); font-family:'microsoft yahei'; font-size:15px; line-height:35px; text-align:start; background-color:rgb(255,255,255)"> <span style="font-size:18px"><span style="font-family:SimSun">其实就是一种查表法。对于输入中的START和END就是指你当前接收到的这个字符串需不需要进行破译处理(显然不需要,所以continue),而对于ENDOFINPUT这个字符串也不是密码,所以break。</span></span></p>
<p style="margin-bottom:0px; padding-top:0px; padding-bottom:0px; word-break:normal; color:rgb(85,85,85); font-family:'microsoft yahei'; font-size:15px; line-height:35px; text-align:start; background-color:rgb(255,255,255)"> <span style="font-size:18px"><span style="font-family:SimSun">在破译处理中,由于'A'对应的应该是V,所以在查表法核心——convert[]数组中第一个写成V,然后到时直接使该字符=convert[字母-'A']即可。</span></span></p>
<p style="margin-bottom:0px; padding-top:0px; padding-bottom:0px; word-break:normal; color:rgb(85,85,85); font-family:'microsoft yahei'; font-size:15px; line-height:35px; text-align:start; background-color:rgb(255,255,255)"> <span style="font-size:18px"><span style="font-family:SimSun"></span></span></p>
<ol class="dp-cpp" start="1" style="padding-left:0px; border-style:none solid none none; border-right-width:1px; border-right-color:rgb(231,229,220); color:rgb(92,92,92); font-family:Consolas,'Courier New',Courier,mono,serif; font-size:12px; line-height:35px; margin-bottom:1px!important; margin-left:45px!important; background-color:rgb(255,255,255)"><li class="alt" style="border-style:none none none solid; border-left-width:3px; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> <span style="margin:0px; padding:0px; border:none; color:black; background-color:inherit"><span class="preprocessor" style="margin:0px; padding:0px; border:none; color:gray; background-color:inherit">#include <stdio.h></span><span style="margin:0px; padding:0px; border:none; background-color:inherit"> </span></span></li><li style="border-style:none none none solid; border-left-width:3px; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important; background-color:rgb(248,248,248)"> <span style="margin:0px; padding:0px; border:none; color:black; background-color:inherit"><span class="preprocessor" style="margin:0px; padding:0px; border:none; color:gray; background-color:inherit">#include <string.h> |
|