如何通過程式設計解決華容道問題?
阿新 • • 發佈:2018-12-11
<div class="rich_media_content" id="js_content">
<p style="color:rgb(51,51,51);font-family:'-apple-system-font', 'system-ui', 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;background-color:rgb(255,255,255);text-align:center;"><span style="color:rgb(136,136,136);font-size:14px;">點選上方“</span><span style="font-size:14px;color:rgb(61,170,214);">程式人生</span><span style="color:rgb(136,136,136);font-size:14px;">”,選擇“置頂公眾號”</span></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', 'system-ui', 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;background-color:rgb(255,255,255);text-align:center;"><span style="color:rgb(136,136,136);font-size:14px;">第一時間關注程式猿(媛)身邊的故事</span></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', 'system-ui', 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;background-color:rgb(255,255,255);"><span style="color:rgb(136,136,136);font-size:14px;"><br></span></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:center;"><img src="https://ss.csdn.net/p?https://mmbiz.qpic.cn/mmbiz_jpg/1eDWTgj1vzctMH7BGDEKicbm0iac5rib21ibsl5ffljKH00F9pdCs9vqvlzNgkicVxctfQcJ8e7PKEAaOFqmzkLmR9Q/640?wx_fmt=jpeg" alt="640?wx_fmt=jpeg"><br></p><p style="text-indent:0em;color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;"><span style="text-indent:32px;color:rgb(136,136,136);font-size:14px;"><br></span></p><p style="text-indent:0em;color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;"><span style="text-indent:32px;color:rgb(136,136,136);font-size:14px;">小史是一個應屆生,雖然學的是電子專業,但是自己業餘時間看了很多網際網路與程式設計方面的書,一心想進</span><span style="text-indent:32px;text-decoration:line-through;color:rgb(136,136,136);font-family:Helvetica, Arial, sans-serif;font-size:14px;">BAT</span><span style="text-indent:32px;font-size:14px;color:rgb(136,136,136);">網際網路公司。</span></p><p style="text-indent:0em;color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;"><span style="text-indent:32px;font-size:14px;color:rgb(136,136,136);"><br></span></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:center;"><img src="https://ss.csdn.net/p?https://mmbiz.qpic.cn/mmbiz_jpg/1eDWTgj1vzctMH7BGDEKicbm0iac5rib21ibNCPcvPeuCawfJmuSnaYv4OMxOh8sGdkDoiasKFI0fyCecJpmibDHbWtg/640?wx_fmt=jpeg" alt="640?wx_fmt=jpeg"></p><p style="color:rgb(105,115,117);"><span style="font-size:13px;text-align:right;color:rgb(61,170,214);font-family:'Optima-Regular', 'PingFangTC-light';">作者</span><br></p><p><span style="color:rgb(136,136,136);font-family:'Optima-Regular', 'PingFangTC-light';letter-spacing:.5px;font-size:13px;"> channingbreeze</span></p><p style="color:rgb(105,115,117);"><span style="color:rgb(204,204,204);font-family:'Optima-Regular', 'PingFangTC-light';font-weight:700;letter-spacing:.5px;text-align:justify;font-size:13px;">已獲原作者授權,如需轉載,請聯絡原作者。</span></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:center;"><br></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;text-indent:0em;">今天他就去一家外企面試了。</p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;text-indent:2em;"><br></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:center;"><img src="https://ss.csdn.net/p?https://mmbiz.qpic.cn/mmbiz_jpg/1eDWTgj1vzctMH7BGDEKicbm0iac5rib21ibl1fxQfViaWB0Vj0XKjPbXwHoZPcBdafZsTeH7YnmY2ibicQWY41bJlK8Q/640?wx_fmt=jpeg" alt="640?wx_fmt=jpeg"></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;text-indent:2em;"><br></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;"><strong><span style="font-size:18px;">【面試前】</span></strong></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;text-indent:0em;"><br></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;text-indent:0em;">面試前,小史就收到了中英文的面試邀請。</p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;text-indent:0em;"><br></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:center;"><img src="https://ss.csdn.net/p?https://mmbiz.qpic.cn/mmbiz_jpg/1eDWTgj1vzctMH7BGDEKicbm0iac5rib21iblqIqSealniaC1FKDicd7CjOY52JMymiclv2pj5TG2iaTic4AfuAuT6TrkRQ/640?wx_fmt=jpeg" alt="640?wx_fmt=jpeg"></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;text-indent:0em;">去外企面試,最好要能夠和麵試官英語對話。小史除了複習演算法之外,趕緊練起了口語。</p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;text-indent:2em;"><br></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:center;"><img src="https://ss.csdn.net/p?https://mmbiz.qpic.cn/mmbiz_jpg/1eDWTgj1vzctMH7BGDEKicbm0iac5rib21ib55SMiatMlOVPLicqfnrIupQrFxCPGq1rHhG9OsibNogAu61gsV0Zg0ezw/640?wx_fmt=jpeg" alt="640?wx_fmt=jpeg"></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:center;"><img src="https://ss.csdn.net/p?https://mmbiz.qpic.cn/mmbiz_jpg/1eDWTgj1vzctMH7BGDEKicbm0iac5rib21ibt91cHl9qchaHjzliaia7pwHZ1eo4zlRzSYhQkQbr18ib5TRbtoJgf82aA/640?wx_fmt=jpeg" alt="640?wx_fmt=jpeg"></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:center;"><img src="https://ss.csdn.net/p?https://mmbiz.qpic.cn/mmbiz_jpg/1eDWTgj1vzctMH7BGDEKicbm0iac5rib21ibBIFIJ4emSMlq5epFmQV9nDekIaYD5WGqc04S5oEibHTDQvGtvHiaiarAw/640?wx_fmt=jpeg" alt="640?wx_fmt=jpeg"></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;text-indent:0em;"><strong><span style="font-size:18px;">【面試現場】</span></strong></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;text-indent:0em;"><strong><span style="font-size:18px;"><br></span></strong></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:center;"><img src="https://ss.csdn.net/p?https://mmbiz.qpic.cn/mmbiz_jpg/1eDWTgj1vzctMH7BGDEKicbm0iac5rib21ibibdicM6Tqb9evKoD1cibKa4jKYLNJyh1txibM6DloZ5Bda6wO4KFIrx92g/640?wx_fmt=jpeg" alt="640?wx_fmt=jpeg"></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;text-indent:0em;"><strong><span style="font-size:18px;"></span></strong></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:center;"><img src="https://ss.csdn.net/p?https://mmbiz.qpic.cn/mmbiz_jpg/1eDWTgj1vzctMH7BGDEKicbm0iac5rib21ibpibVCL2D07JKEAFvRolZ6iaEyRia1ThcWlBzDHSVDSPovMN6xsicwywM5Q/640?wx_fmt=jpeg" alt="640?wx_fmt=jpeg"></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:center;"><img src="https://ss.csdn.net/p?https://mmbiz.qpic.cn/mmbiz_jpg/1eDWTgj1vzctMH7BGDEKicbm0iac5rib21ibEGaHYkIdM9wVRhlTcAPbBOcdNfm1QDqhicyKofQHlDyx6Cj9Fw3kc9A/640?wx_fmt=jpeg" alt="640?wx_fmt=jpeg"></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;text-indent:0em;">面試官給了小史一個問題。(題目已翻譯成中文,請自行腦補英文現場)</p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;text-indent:2em;"><br></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;text-indent:0em;"><span style="font-size:18px;font-weight:700;text-indent:32px;">題目:我</span><span style="font-size:18px;font-weight:700;">有1到8八個數字,放在一個3x3的九宮格里面,那麼會留下一個空格。</span></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:center;"><img src="https://ss.csdn.net/p?https://mmbiz.qpic.cn/mmbiz_jpg/1eDWTgj1vzctMH7BGDEKicbm0iac5rib21ibN8EL3hoTYdCN34zURny9afic9abcYSlJcDjUHo9we8myRBc2QOgMmDw/640?wx_fmt=jpeg" alt="640?wx_fmt=jpeg"></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;text-indent:0em;"><span style="font-size:18px;font-weight:700;">空格可以和上下左右的數字進行交換,你可以認為空格在移動。如果移動成</span></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:center;"><img src="https://ss.csdn.net/p?https://mmbiz.qpic.cn/mmbiz_jpg/1eDWTgj1vzctMH7BGDEKicbm0iac5rib21ibTUQHC8PNnXyeLBMalT52iceMxAySImGLm9vvibCmr18s4ydic5qonibtkw/640?wx_fmt=jpeg" alt="640?wx_fmt=jpeg"></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;text-indent:0em;"><span style="font-size:18px;font-weight:700;">則遊戲勝利。</span></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;text-indent:0em;"><span style="font-size:18px;font-weight:700;">你需要完成以下2件事情:</span></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;text-indent:0em;"><span style="font-size:18px;font-weight:700;">1、給出資料結構來描述這個過程。</span></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;text-indent:0em;"><span style="font-size:18px;font-weight:700;">2、給你一個初始狀態,告訴我能不能勝利,並給出如何移動才能勝利。</span></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;text-indent:0em;"><span style="font-size:18px;font-weight:700;">這有點像咱們中國的華容道遊戲。</span></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:center;"><img src="https://ss.csdn.net/p?https://mmbiz.qpic.cn/mmbiz_jpg/1eDWTgj1vzctMH7BGDEKicbm0iac5rib21ibmicDXT0HuJHRvTk5sksFIC5tQria1Fib4GuKlzMsCI6CaMAHb1vdtxhaA/640?wx_fmt=jpeg" alt="640?wx_fmt=jpeg"></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;text-indent:0em;"><span style="font-size:18px;font-weight:700;"></span></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:center;"><img src="https://ss.csdn.net/p?https://mmbiz.qpic.cn/mmbiz_jpg/1eDWTgj1vzctMH7BGDEKicbm0iac5rib21ibZM4yibKfwZpvwiaKPjnGCuEkM5DqRSGEqtmOIIZMuRlaLqMHiajf4bjLA/640?wx_fmt=jpeg" alt="640?wx_fmt=jpeg"></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:center;"><img src="https://ss.csdn.net/p?https://mmbiz.qpic.cn/mmbiz_jpg/1eDWTgj1vzctMH7BGDEKicbm0iac5rib21ibia86TRDs7lG1fDZZZzqPm917ntpUbC1Zh0UdmzVcdabc42hBzIQMb5w/640?wx_fmt=jpeg" alt="640?wx_fmt=jpeg"></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;text-indent:2em;"><span style="font-size:18px;font-weight:700;text-indent:32px;"></span></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:center;"><img src="https://ss.csdn.net/p?https://mmbiz.qpic.cn/mmbiz_jpg/1eDWTgj1vzctMH7BGDEKicbm0iac5rib21ibewNyK2vMTFaadLoqMuuWb30mVjHMoNqRv6TQOIhd7dsZjj42wvE0HA/640?wx_fmt=jpeg" alt="640?wx_fmt=jpeg"></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:center;"><img src="https://ss.csdn.net/p?https://mmbiz.qpic.cn/mmbiz_jpg/1eDWTgj1vzctMH7BGDEKicbm0iac5rib21ibzvTwMHAOibBP3vexP5huQXEOplYSLg5fbSibj6OckMRIPDEngquLj6ZA/640?wx_fmt=jpeg" alt="640?wx_fmt=jpeg"></p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;text-indent:0em;">小史把他能想到的都寫了下來。</p><p style="color:rgb(51,51,51);font-family:'-apple-system-font', BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif;font-size:17px;letter-spacing:.544px;text-align:justify;text-indent:2em;"><br></p><pre style="font-size:inherit;color:inherit;line-height:inherit;" onclick="hljs.copyCode(event)"><code style="margin-left:2px;line-height:18px;font-size:14px;letter-spacing:0px;font-family:Consolas, Inconsolata, Courier, monospace;color:rgb(169,183,198);background-color:rgb(40,43,46);" class="hljs vbscript-html"><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">import</span></span><span class="xml"> java.util.LinkedList;</span><br><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">import</span></span><span class="xml"> java.util.List;</span><br><br><span style="font-size:inherit;line-height:inherit;color:rgb(128,128,128);"><span class="xml">/**</span><br><span class="xml"> * </span><span style="font-size:inherit;color:inherit;line-height:inherit;"><span class="xml">@author</span></span><span class="xml"> xiaoshi on 2018/9/8.</span><br><span class="xml"> */</span></span><br><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">public</span></span><span class="xml"> </span><span style="font-size:inherit;color:inherit;line-height:inherit;"><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">class</span></span><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(165,218,45);"><span class="xml">HuaRongDao</span></span><span class="xml"> </span></span><span class="xml">{</span><br><br><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(128,128,128);"><span class="xml">// 定義方向</span></span><br><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">public</span></span><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">static</span></span><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">final</span></span><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">int</span></span><span class="xml"> LEFT = </span><span style="font-size:inherit;line-height:inherit;color:rgb(174,135,250);"><span class="xml">1</span></span><span class="xml">;</span><br><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">public</span></span><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">static</span></span><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">final</span></span><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">int</span></span><span class="xml"> RIGHT = </span><span style="font-size:inherit;line-height:inherit;color:rgb(174,135,250);"><span class="xml">2</span></span><span class="xml">;</span><br><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">public</span></span><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">static</span></span><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">final</span></span><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">int</span></span><span class="xml"> UP = </span><span style="font-size:inherit;line-height:inherit;color:rgb(174,135,250);"><span class="xml">3</span></span><span class="xml">;</span><br><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">public</span></span><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">static</span></span><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">final</span></span><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">int</span></span><span class="xml"> DOWN = </span><span style="font-size:inherit;line-height:inherit;color:rgb(174,135,250);"><span class="xml">4</span></span><span class="xml">;</span><br><br><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(128,128,128);"><span class="xml">// 3x3的九宮格</span></span><br><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">private</span></span><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">int</span></span><span class="xml">[][] arr;</span><br><br><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(128,128,128);"><span class="xml">// 記錄空格的位置</span></span><br><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">private</span></span><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">int</span></span><span class="xml"> x;</span><br><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">private</span></span><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">int</span></span><span class="xml"> y;</span><br><br><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(128,128,128);"><span class="xml">// 定義移動的陣列</span></span><br><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">private</span></span><span class="xml"> List<span class="hljs-tag"><<span class="hljs-name">Integer</span>></span> moveArr = </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">new</span></span><span class="xml"> LinkedList<span class="hljs-tag"><<span class="hljs-name">Integer</span>></span>();</span><br><br><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(128,128,128);"><span class="xml">// 初始化,數字0代表空格,先遍歷,找出空格的位置</span></span><br><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span style="font-size:inherit;line-height:inherit;"><span class="xml">public</span></span><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(165,218,45);"><span class="xml">HuaRongDao</span></span><span style="font-size:inherit;line-height:inherit;color:rgb(255,152,35);"><span class="xml">(</span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">int</span></span><span class="xml">[][] arr)</span></span><span class="xml"> </span></span><span class="xml">{</span><br><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">this</span></span><span class="xml">.arr = arr;</span><br><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">for</span></span><span class="xml">(</span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">int</span></span><span class="xml"> i=</span><span style="font-size:inherit;line-height:inherit;color:rgb(174,135,250);"><span class="xml">0</span></span><span class="xml">; i<span class="hljs-tag"><<span class="hljs-name">arr.length;</span> <span class="hljs-attr">i</span>++) {</span></span><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">for</span></span></span></span><span class="xml"><span class="hljs-tag">(</span></span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">int</span></span></span></span><span class="xml"><span class="hljs-tag"> <span class="hljs-attr">j</span>=</span></span><span style="font-size:inherit;line-height:inherit;color:rgb(174,135,250);"><span class="xml"><span class="hljs-tag"><span class="hljs-string">0</span></span></span></span><span class="xml"><span class="hljs-tag"><span class="hljs-string">;</span> <span class="hljs-attr">j</span><<span class="hljs-attr">arr.length</span>; <span class="hljs-attr">j</span>++) {</span></span><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">if</span></span></span></span><span class="xml"><span class="hljs-tag">(<span class="hljs-attr">arr</span>[<span class="hljs-attr">i</span>][<span class="hljs-attr">j</span>] == </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(174,135,250);"><span class="xml"><span class="hljs-tag"><span class="hljs-string">0</span></span></span></span><span class="xml"><span class="hljs-tag"><span class="hljs-string">)</span> {</span></span><br><span class="xml"><span class="hljs-tag"> <span class="hljs-attr">x</span> = <span class="hljs-string">i;</span></span></span><br><span class="xml"><span class="hljs-tag"> <span class="hljs-attr">y</span> = <span class="hljs-string">j;</span></span></span><br><span class="xml"><span class="hljs-tag"> }</span></span><br><span class="xml"><span class="hljs-tag"> }</span></span><br><span class="xml"><span class="hljs-tag"> }</span></span><br><span class="xml"><span class="hljs-tag"> }</span></span><br><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(128,128,128);"><span class="xml"><span class="hljs-tag">// 判斷是否可以朝某個方向進行移動</span></span></span><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span style="font-size:inherit;line-height:inherit;"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">public</span></span></span></span><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">boolean</span></span></span></span><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(165,218,45);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">canMove</span></span></span></span><span style="font-size:inherit;line-height:inherit;color:rgb(255,152,35);"><span class="xml"><span class="hljs-tag">(</span></span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">int</span></span></span></span><span class="xml"><span class="hljs-tag"> <span class="hljs-attr">direction</span>)</span></span></span><span class="xml"><span class="hljs-tag"> </span></span></span><span class="xml"><span class="hljs-tag">{</span></span><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">switch</span></span></span></span><span class="xml"><span class="hljs-tag"> (<span class="hljs-attr">direction</span>) {</span></span><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(128,128,128);"><span class="xml"><span class="hljs-tag">// <span class="hljs-attr">y</span> ></span> 0才能左移</span></span><br><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">case</span></span><span class="xml"> LEFT:</span><br><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">return</span></span><span class="xml"> y > </span><span style="font-size:inherit;line-height:inherit;color:rgb(174,135,250);"><span class="xml">0</span></span><span class="xml">;</span><br><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(128,128,128);"><span class="xml">// y <span class="hljs-tag">< <span class="hljs-attr">2</span>才能右移</span></span></span><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">case</span></span></span></span><span class="xml"><span class="hljs-tag"> <span class="hljs-attr">RIGHT:</span></span></span><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">return</span></span></span></span><span class="xml"><span class="hljs-tag"> <span class="hljs-attr">y</span> < </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(174,135,250);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">2</span></span></span></span><span class="xml"><span class="hljs-tag">;</span></span><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(128,128,128);"><span class="xml"><span class="hljs-tag">// <span class="hljs-attr">x</span> ></span> 0才能上移</span></span><br><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">case</span></span><span class="xml"> UP:</span><br><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml">return</span></span><span class="xml"> x > </span><span style="font-size:inherit;line-height:inherit;color:rgb(174,135,250);"><span class="xml">0</span></span><span class="xml">;</span><br><span class="xml"> </span><span style="font-size:inherit;line-height:inherit;color:rgb(128,128,128);"><span class="xml">// x <span class="hljs-tag">< <span class="hljs-attr">2</span>才能下移</span></span></span><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">case</span></span></span></span><span class="xml"><span class="hljs-tag"> <span class="hljs-attr">DOWN:</span></span></span><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">return</span></span></span></span><span class="xml"><span class="hljs-tag"> <span class="hljs-attr">x</span> < </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(174,135,250);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">2</span></span></span></span><span class="xml"><span class="hljs-tag">;</span></span><br><span class="xml"><span class="hljs-tag"> }</span></span><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">return</span></span></span></span><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">false</span></span></span></span><span class="xml"><span class="hljs-tag">;</span></span><br><span class="xml"><span class="hljs-tag"> }</span></span><br><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(128,128,128);"><span class="xml"><span class="hljs-tag">// 朝某個方向進行移動,該函式不作判斷,直接移動</span></span></span><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(128,128,128);"><span class="xml"><span class="hljs-tag">// 呼叫前請自行用<span class="hljs-attr">canMove</span>先行判斷</span></span></span><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span style="font-size:inherit;line-height:inherit;"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">public</span></span></span></span><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">void</span></span></span></span><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(165,218,45);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">move</span></span></span></span><span style="font-size:inherit;line-height:inherit;color:rgb(255,152,35);"><span class="xml"><span class="hljs-tag">(</span></span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">int</span></span></span></span><span class="xml"><span class="hljs-tag"> <span class="hljs-attr">direction</span>)</span></span></span><span class="xml"><span class="hljs-tag"> </span></span></span><span class="xml"><span class="hljs-tag">{</span></span><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">int</span></span></span></span><span class="xml"><span class="hljs-tag"> <span class="hljs-attr">temp</span>;</span></span><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">switch</span></span></span></span><span class="xml"><span class="hljs-tag"> (<span class="hljs-attr">direction</span>) {</span></span><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(128,128,128);"><span class="xml"><span class="hljs-tag">// 空格和左側數字交換</span></span></span><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">case</span></span></span></span><span class="xml"><span class="hljs-tag"> <span class="hljs-attr">LEFT:</span></span></span><br><span class="xml"><span class="hljs-tag"> <span class="hljs-attr">temp</span> = <span class="hljs-string">arr[x][y</span> <span class="hljs-attr">-</span> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(174,135,250);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">1</span></span></span></span><span class="xml"><span class="hljs-tag">];</span></span><br><span class="xml"><span class="hljs-tag"> <span class="hljs-attr">arr</span>[<span class="hljs-attr">x</span>][<span class="hljs-attr">y</span> <span class="hljs-attr">-</span> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(174,135,250);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">1</span></span></span></span><span class="xml"><span class="hljs-tag">] = </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(174,135,250);"><span class="xml"><span class="hljs-tag"><span class="hljs-string">0</span></span></span></span><span class="xml"><span class="hljs-tag"><span class="hljs-string">;</span></span></span><br><span class="xml"><span class="hljs-tag"> <span class="hljs-attr">arr</span>[<span class="hljs-attr">x</span>][<span class="hljs-attr">y</span>] = <span class="hljs-string">temp;</span></span></span><br><span class="xml"><span class="hljs-tag"> <span class="hljs-attr">y</span> = <span class="hljs-string">y</span> <span class="hljs-attr">-</span> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(174,135,250);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">1</span></span></span></span><span class="xml"><span class="hljs-tag">;</span></span><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">break</span></span></span></span><span class="xml"><span class="hljs-tag">;</span></span><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(128,128,128);"><span class="xml"><span class="hljs-tag">// 空格和右側數字交換</span></span></span><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">case</span></span></span></span><span class="xml"><span class="hljs-tag"> <span class="hljs-attr">RIGHT:</span></span></span><br><span class="xml"><span class="hljs-tag"> <span class="hljs-attr">temp</span> = <span class="hljs-string">arr[x][y</span> + </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(174,135,250);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">1</span></span></span></span><span class="xml"><span class="hljs-tag">];</span></span><br><span class="xml"><span class="hljs-tag"> <span class="hljs-attr">arr</span>[<span class="hljs-attr">x</span>][<span class="hljs-attr">y</span> + </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(174,135,250);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">1</span></span></span></span><span class="xml"><span class="hljs-tag">] = </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(174,135,250);"><span class="xml"><span class="hljs-tag"><span class="hljs-string">0</span></span></span></span><span class="xml"><span class="hljs-tag"><span class="hljs-string">;</span></span></span><br><span class="xml"><span class="hljs-tag"> <span class="hljs-attr">arr</span>[<span class="hljs-attr">x</span>][<span class="hljs-attr">y</span>] = <span class="hljs-string">temp;</span></span></span><br><span class="xml"><span class="hljs-tag"> <span class="hljs-attr">y</span> = <span class="hljs-string">y</span> + </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(174,135,250);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">1</span></span></span></span><span class="xml"><span class="hljs-tag">;</span></span><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">break</span></span></span></span><span class="xml"><span class="hljs-tag">;</span></span><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(128,128,128);"><span class="xml"><span class="hljs-tag">// 空格和上方數字交換</span></span></span><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">case</span></span></span></span><span class="xml"><span class="hljs-tag"> <span class="hljs-attr">UP:</span></span></span><br><span class="xml"><span class="hljs-tag"> <span class="hljs-attr">temp</span> = <span class="hljs-string">arr[x</span> <span class="hljs-attr">-</span> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(174,135,250);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">1</span></span></span></span><span class="xml"><span class="hljs-tag">][<span class="hljs-attr">y</span>];</span></span><br><span class="xml"><span class="hljs-tag"> <span class="hljs-attr">arr</span>[<span class="hljs-attr">x</span> <span class="hljs-attr">-</span> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(174,135,250);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">1</span></span></span></span><span class="xml"><span class="hljs-tag">][<span class="hljs-attr">y</span>] = </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(174,135,250);"><span class="xml"><span class="hljs-tag"><span class="hljs-string">0</span></span></span></span><span class="xml"><span class="hljs-tag"><span class="hljs-string">;</span></span></span><br><span class="xml"><span class="hljs-tag"> <span class="hljs-attr">arr</span>[<span class="hljs-attr">x</span>][<span class="hljs-attr">y</span>] = <span class="hljs-string">temp;</span></span></span><br><span class="xml"><span class="hljs-tag"> <span class="hljs-attr">x</span> = <span class="hljs-string">x</span> <span class="hljs-attr">-</span> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(174,135,250);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">1</span></span></span></span><span class="xml"><span class="hljs-tag">;</span></span><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">break</span></span></span></span><span class="xml"><span class="hljs-tag">;</span></span><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(128,128,128);"><span class="xml"><span class="hljs-tag">// 空格和下方數字交換</span></span></span><br><span class="xml"><span class="hljs-tag"> </span></span><span style="font-size:inherit;line-height:inherit;color:rgb(248,35,117);"><span class="xml"><span class="hljs-tag"><span class="hljs-attr">case</span></span></span></span><span class="xml"><span class="hljs-tag"> <span class="hljs-attr">DOWN:</span></span></span><br><span class="xml"><span class="hljs-tag"> <span class="hljs-attr">temp</span> = <sp