<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Algorithms on Lin's Blog</title><link>https://coder.tw/tags/algorithms/</link><description>Recent content in Algorithms on Lin's Blog</description><generator>Hugo</generator><language>zh-TW</language><lastBuildDate>Sun, 05 Jun 2011 01:00:07 +0000</lastBuildDate><atom:link href="https://coder.tw/tags/algorithms/index.xml" rel="self" type="application/rss+xml"/><item><title>洗牌演算法（交換法）</title><link>https://coder.tw/posts/shuffle-algorithm-swap-method/</link><pubDate>Sun, 05 Jun 2011 01:00:07 +0000</pubDate><guid>https://coder.tw/posts/shuffle-algorithm-swap-method/</guid><description>&lt;p&gt;&lt;a href="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/06/2011-06-05_005920.jpg"&gt;&lt;img class="size-large wp-image-534 aligncenter" title="2011-06-05_005920" src="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/06/2011-06-05_005920-540x352.jpg" alt="" width="540" height="352" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;洗牌演算法就是可以產生不重複的亂數的一種演算法，舉例來講如果要產生十個亂數，並且這十個亂數必須是「不重複」的，那很多人的直覺是用rand函式取得一個亂數值以後，存入陣列，並且跟陣列內以有的數字做比對，這種方法簡單是簡單，但是效能很差，而這裡要介紹的洗牌演算法效能跟剛剛講的方法可說是天差地遠，洗牌演算法的原理其實很簡單，就是先在陣列裡存入數字，然後將數字打散&lt;/p&gt;</description></item><item><title>【C++】數字翻轉、字串翻轉(應用：轉型別、字串處理、迴圈)</title><link>https://coder.tw/posts/c-reverse-number-and-string/</link><pubDate>Sun, 06 Mar 2011 11:18:22 +0000</pubDate><guid>https://coder.tw/posts/c-reverse-number-and-string/</guid><description>&lt;p&gt;&lt;a href="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/03/2011-03-06_111510.jpg"&gt;&lt;img class="size-large wp-image-342 aligncenter" title="2011-03-06_111510" src="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/03/2011-03-06_111510-540x382.jpg" alt="" width="540" height="382" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;這算是蠻簡單的題目，就只是做數字or字串的翻轉，例如輸入：linroex會輸出：xeornil或是輸入123會傳回321，這題解法並不難，透過C++裡面字串可以用陣列的方式存取這個特性，我們設定一個迴圈，然後取得輸入字串的長度作為迴圈的結束值，接者當迴圈跑一圈時就把X字串最後一個字移到Y字串第一個字，這樣當迴圈跑完時就翻轉完成了&lt;/p&gt;
&lt;p&gt;</description></item><item><title>【VB】【C++】計算n!(階層)</title><link>https://coder.tw/posts/vb-c-factorial-n-2/</link><pubDate>Wed, 05 Jan 2011 05:58:10 +0000</pubDate><guid>https://coder.tw/posts/vb-c-factorial-n-2/</guid><description>&lt;p&gt;&lt;a href="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/01/2011-01-05_054100.jpg"&gt;&lt;img class="alignnone size-large wp-image-4369" title="2011-01-05_054100" src="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/01/2011-01-05_054100-520x253.jpg" alt="" width="520" height="253" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;要計算n的階層是很簡單的一件事,會寫到這個程式是因為排列組合,我想要精確的知道答案會在幾種左右,因此就寫了n!的函數來幫忙求階層的值,所謂的階層就是指從1&lt;em&gt;2&lt;/em&gt;3&amp;hellip;..&lt;em&gt;n的意思,而在排列組合中如果要被排列的字有5個字,那麼排列後的結果就最多不超過5&lt;/em&gt;4&lt;em&gt;3&lt;/em&gt;2*1的值,也就是最多不超過120個答案&lt;/p&gt;
&lt;p&gt;以下我把n!做成Function,有VB版的跟C++版的,剛開始學迴圈的人可以用這個函式來學習迴圈的用法,另外因為擔心integer會存不下資料,所以我使用string來傳回資料,到時候用這個Function時要先把傳回值轉成數字型別才可以&lt;/p&gt;
&lt;h2&gt;</description></item></channel></rss>