<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Irene H on Medium]]></title>
        <description><![CDATA[Stories by Irene H on Medium]]></description>
        <link>https://medium.com/@happyirenehu?source=rss-4cf426519472------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*snd29s19tAHssSAQn_OOXQ.png</url>
            <title>Stories by Irene H on Medium</title>
            <link>https://medium.com/@happyirenehu?source=rss-4cf426519472------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 13:40:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@happyirenehu/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[超討厭套版人之把所有東西暴力拆開來菜鳥筆記： 電腦科學大一統之路Assembly的藝術]]></title>
            <link>https://medium.com/@happyirenehu/%E8%B6%85%E8%A8%8E%E5%8E%AD%E5%A5%97%E7%89%88%E4%BA%BA%E4%B9%8B%E6%8A%8A%E6%89%80%E6%9C%89%E6%9D%B1%E8%A5%BF%E6%9A%B4%E5%8A%9B%E6%8B%86%E9%96%8B%E4%BE%86%E8%8F%9C%E9%B3%A5%E7%AD%86%E8%A8%98-%E9%9B%BB%E8%85%A6%E7%A7%91%E5%AD%B8%E5%A4%A7%E4%B8%80%E7%B5%B1%E4%B9%8B%E8%B7%AFassembly%E7%9A%84%E8%97%9D%E8%A1%93-b9f11b4cdf92?source=rss-4cf426519472------2</link>
            <guid isPermaLink="false">https://medium.com/p/b9f11b4cdf92</guid>
            <dc:creator><![CDATA[Irene H]]></dc:creator>
            <pubDate>Tue, 20 Oct 2026 09:31:49 GMT</pubDate>
            <atom:updated>2026-10-20T09:31:49.308Z</atom:updated>
            <content:encoded><![CDATA[<p>前言：有很多介紹，請略過以下，直接去“小小兵的規則簡介”看怎麼用。</p><p>Assembly呢，基本就是一切“電”做的腦的祖宗之一，我們大一吐血學計算機概論的源頭。</p><p>（額當然，二進位大神才是開天闢地祖師爺，這個Assembly叫他…祖宗好了，祖師爺的後代。</p><p>女媧/上帝 → 二進位</p><p>祖宗 → assembly</p><p>現代 → 程式語言（跟祖宗中間有個編譯器之類的，或是可稱為翻譯機，語言不通）</p><p>21世紀→ 電腦直接自己寫 XD</p><h3>物種起源</h3><p>資料結構跟演算法？</p><p>資料庫各種東東？</p><p>C/C++, JavaScript, Rust, Ruby on Rails 到Vue?</p><p>LLVM or GNC?</p><p>系統架構?雲端架構?機器學習？</p><p>都是他啦。</p><p>Lego世界的超級star wars戰艦跟迪士尼城堡也是一堆小小積木組合成的。</p><p>戰爭中有軍官，軍營，小兵。</p><p>Assembly就是小小兵。</p><p>（碎碎念：你看哈比人，看不到他的功勞跟苦勞，但沒有他，中土世界就毀滅了，雖然光芒都在精靈跟國王身上，精靈真的好美）</p><p>那小小兵每日日常（aka程式的日常)，就是<strong><em>搬東西，比一比，看一眼，跳出來。</em></strong></p><h3>小小兵的規則簡介</h3><h3>指令：</h3><p>mov 移動</p><p>push 壓進去</p><p>pop 噴出來</p><p>（Push, pop都是函數function()時常見的，那Mov有什麼區別啊？ 很類似，但區別是這是單純stack指令，跟mov移動，但要告訴去哪兒搬去隔壁沾板還是去記憶體，stack只要無腦一丟，就會自動飛到“stack專屬空間”，但這空間呢有限，會一直被下一個任務蓋掉，stack就是只有固定專屬一定的空間。）</p><p>注意：他們小小兵權限有限，只能拿記憶體跟沾板東西。直接拿不到硬碟的，要靠別人幫忙。</p><h3>算數時間：</h3><p>add/sub 加減</p><p>mul/div 乘除</p><p>那有這堆指令，我們要有空間，那分為兩種空間，CPU的暫存空間（沾板），跟記憶體/硬碟中的固定空間。</p><h3>沾板：</h3><p>eax, rax, edi ….. 沾板有幾個取決於幾個位元，32位元有8個，64位元有16個！</p><p><strong><em>重點：每一個粘版只能擺8 byte的東西（64位元下），超過8就擺不下(例如 int, char, pointer裝得下）。</em></strong></p><p>固定空間：看到有這個動作 mov [記憶體空間], eax 就是表示把沾板的東西搬進記憶體了。</p><p>但是，重點來了，如果是超過8 byte，搬不動啊，怎麼辦呢？</p><p>分兩個粘版？多次慢慢搬？可以，分次搬可以，CPU一直重複直到完成，很累。</p><p>另一種更聰明的方法（感謝前輩大神讓我們不用再出去租DVD），他們發明了pointer，像串流這樣，可以把一個4K HDR的影片，在網上看，就是用到傳“地址“，而不是整個本人搬進來，eax等等沾板可以慢慢搬，邊看邊搬下一段落，也是感謝硬體網路現在超級快才能達成串流。</p><h3>靈魂function函數用的各種比較等於</h3><p>現在來重頭戲，比較，函數就是各種比來比去。</p><p>cmp 比較本人</p><p>jmp 跳到哪去</p><p>je 只要等於就跳轉</p><h3>施工環境</h3><p>來，最後我們介紹一下有哪些地方能施工，有哪些地圖給小小兵開工。</p><p><strong>施工專區</strong> <strong>Assembly 看到的樣子</strong> 說明 <strong>誰負責清理？</strong></p><ol><li><strong>Stack (棧)</strong> [ebp-4], [esp] <strong>臨時工具架</strong>。就在手邊，拿放極快。 <strong>自動</strong>（函式結束，指標一拉就沒了）。</li><li><strong>2. Heap (堆)</strong> [eax] (EAX 存的是 malloc 回來的地址) <strong>大型工地</strong>。要先申請才能用，空間超大。 <strong>手動</strong>（不喊 free，它就永遠在那）。</li><li><strong>3. Static/Data (全域)</strong> [0x401000] (固定的絕對地址) <strong>百年老店</strong>。程式一開就在那，程式關掉才消失。 <strong>系統</strong>（程式結束才清）。</li></ol><p>所以基本上，static就是實際去那個”地址“搬出東西，最慢，你沒辦法直接刪，要手動kill。</p><p>heap是一個共用的大型工地，很多人能一起用，空間是固定的，不刪掉會爆掉喔，要記得清理。</p><p>stack通常一個人用一個，用完不會消失，是被下一個蓋掉。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b9f11b4cdf92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Recursive function C++新手村IV]]></title>
            <link>https://medium.com/@happyirenehu/recursive-function-c-%E6%96%B0%E6%89%8B%E6%9D%91iv-8652cc0c4441?source=rss-4cf426519472------2</link>
            <guid isPermaLink="false">https://medium.com/p/8652cc0c4441</guid>
            <dc:creator><![CDATA[Irene H]]></dc:creator>
            <pubDate>Mon, 12 Sep 2022 18:35:10 GMT</pubDate>
            <atom:updated>2022-09-12T18:45:28.929Z</atom:updated>
            <content:encoded><![CDATA[<p>今天，來到hacker rank第n天，前幾天在放空及複習之前學過的資料結構，<br>稍微讓大腦放鬆一下。</p><p>首先，什麼是recursive function? recursive algorithm有什麼用處？</p><p>就是另一種，不用looping來幫助我們讓電腦重複計算的一個方式。</p><blockquote>例如Iterating就是一種簡化的方式，for(var i = 0;i&lt;5;i++) 給電腦一個特定的範圍，告訴電腦在這個範圍內做出我們指派的運算。</blockquote><p>想想電腦的本質就是重複計算，人腦很聰明，但速度有限，電腦可以崩崩崩算出n千萬的可能，圖靈發明的那個機器就是為了要”重複重複重複“破解德軍密碼而建造的。</p><p>而recursion很簡單，就是讓 function自己呼叫自己（自call的概念），自體重複，自體循環。</p><pre>#include &lt;iostream&gt;</pre><pre>using namespace std;<br>int recursive(int m, int n){<br>    if(m == n){<br>        return m;<br>    } //上面是指定範圍 像i &lt; 5這樣，防止無止境的loop下去<br>    return m * recursive(m+1,n); <br>   //自體循環本尊，m*(m+1*(m+1*(m+1(...))之循環直到！上面的指定範圍達到為止<br>}</pre><pre>int main() {<br>    int x=1;<br>    int y=7;</pre><pre>cout&lt;&lt;&quot;Factorial of number = &quot; &lt;&lt; recursive(x,y);<br>}<br>//Factorial of number = 5040</pre><p>Reference: Code Beauty(Youtube)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8652cc0c4441" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[C++新手村學習筆記-Vector和Array]]></title>
            <link>https://medium.com/@happyirenehu/c-%E6%96%B0%E6%89%8B%E6%9D%91%E5%AD%B8%E7%BF%92%E7%AD%86%E8%A8%98-vector%E5%92%8Carray-ff857bfa26b3?source=rss-4cf426519472------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff857bfa26b3</guid>
            <dc:creator><![CDATA[Irene H]]></dc:creator>
            <pubDate>Sat, 03 Sep 2022 10:22:27 GMT</pubDate>
            <atom:updated>2022-09-03T10:22:27.402Z</atom:updated>
            <content:encoded><![CDATA[<p>Array v.s Vector大找碴！</p><p>每次都被這兩種弄糊塗，決定來記錄一下過程。</p><p><a href="https://leetcode.com/problems/fizz-buzz/">https://leetcode.com/problems/fizz-buzz/</a> string刷題</p><p>可以注意一下自己debug時是邏輯出問題，還是語法，很灰心以為是邏輯有問題，結果常常最後一看發現都是錯語法啊～ 不要因為不自信一直去改正確的邏輯，反而越寫越錯了。</p><blockquote>前言</blockquote><p>看到接下來學期要學C++其實是覺得有點怕怕的，因為同學都說這門Object-oriented Programming是Level 5最難的課之一，另外還有幾門課用Java教，很難又很燒時間，決定趁暑假來預習一下。雖然我的JS才剛剛摸一點點熟，結果意外的發現C++雖然號稱初學者不友善，但讓我學到很多之前在寫JavaScrip很模糊的概念，尤其是資料結構，Boolean、string、character、interger、double等等，現在才理解為什麼資料不定義清楚時會未知的原因跑不動。而且C++還有個好處，寫邏輯的時候很直觀，可以先好好思考要用哪種資料喂給電腦，而不是在JS那樣直接let、 var、const下去一個variable。C++在degug的時候真的比較複雜，有許多眉角要注意，但總體來說學的很值得，不知道為何同樣的題目，比用JS理解資料結構跟演算法簡單多了，可能是JS是compile後的所以為了方便省掉很多步驟，尤其ES6更加精簡化的情況，更加難以理解。</p><p>首先來聊聊Array，他是fixed的，就是”要跟他說需要多少空間“:</p><p>std::array&lt;int, 2&gt; array{1,2}; 或是std::array&lt;int, 2&gt;array = {1,2};</p><p>但新的C++17版本改成這樣:</p><p>std::array Array { 9, 7, 5, 3, 1 }; //The type is deduced to std::array&lt;int, 5&gt; 簡化版本</p><p>Ｃ++20版本現在暫且不提，對新手來說太複雜拉～</p><p>然後呢，array還可以這樣用</p><p>std::array&lt;int, 5&gt; num;</p><p>num ={1,2,3,4,5}; `</p><p>如果只給num ={1,2,3}也是ok的，後面空的地方會自動設為“零”，出來長這樣{1,2,3,0,0}</p><p>要挖出裡面的資料跟JS一樣，num[1] 這樣就是取出array的第二個位子的資料。</p><p>？那那那，num ＝ [1]跟num = (1)有什麼不同？</p><p>要注意，不能直接std::cout &lt;&lt; array_name;，印不出東西的，要用loop去跑，因為array是一格一格一個物件，像是不同套房是不同門牌，送包裹要一間一間通知。</p><p>string、int、double這種才能直接印出來，類似一間公寓有不同房間但有同樣的大門，相同門牌，送包裹時只要按公寓門鈴裡面的人就都能知道了。但都能用name [index];呼叫該資料喔！</p><p>＊＊添加東西進去array不能用push_back()（vector可以），要用array_name[想要放的位子] = （東西）;</p><p>Vector不用定義需要多少空間，because it’s dynamic.</p><p>如何添加東西:</p><ol><li>可以用vector_name.push_back(想添加的東西);</li></ol><p>2. 或是直接assign ，例如 vector_name{1,2,3};</p><pre>int main()<br>{<br> std::vector&lt;int&gt; arr{1,2,3,4,5,6};<br> //int sum;<br> std::vector&lt;int&gt; sum{};<br> for(int i =1;i &lt; arr.size();i++){<br> arr[i] = arr[i] + arr[i-1];<br> }</pre><pre> for (int i : arr) //literate the array out <br> std::cout &lt;&lt; i &lt;&lt; ‘ ‘;<br> std::cout &lt;&lt; ‘\n’;<br>}</pre><p>這種不好，會把原本參數改掉，最好做一個新vector的放，注意sytax，每次都是語法的問題喔，邏輯是對的不要灰心。</p><p>聊聊string~ 轉自Stack overflow</p><p>std::string provides operator[] to access a character by index:</p><p><a href="https://en.cppreference.com/w/cpp/string/basic_string/operator_at">https://en.cppreference.com/w/cpp/string/basic_string/operator_at</a></p><p>Example:</p><pre>const std::string s(&quot;hello&quot;);<br>const char c = s[0];<br>// c is set to ‘h’ </pre><pre>類似於vector的方法也考以用.push_back()插入。</pre><p>std::string string_name {}; 等於 std::string string_name= {}; //空的string</p><p>reverse.push_back(text[i]); 等於 reverse ＋＝text [i]; //添加東西</p><pre>0.024542(inline) vs 0.025474(none-inline)</pre><p>inline 可以用來縮短執行時間，可以直接把cpp裡面很短的function直接打在declare的hpp裡面</p><p>像醬 inline function_name(parameter){ 動作 };</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff857bfa26b3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[this到底是什麼？新手村之C++物件導向II]]></title>
            <link>https://medium.com/@happyirenehu/this%E5%88%B0%E5%BA%95%E6%98%AF%E4%BB%80%E9%BA%BC-%E6%96%B0%E6%89%8B%E6%9D%91%E4%B9%8Bc-%E7%89%A9%E4%BB%B6%E5%B0%8E%E5%90%91ii-2e3c75d9fa84?source=rss-4cf426519472------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e3c75d9fa84</guid>
            <dc:creator><![CDATA[Irene H]]></dc:creator>
            <pubDate>Thu, 01 Sep 2022 18:52:21 GMT</pubDate>
            <atom:updated>2022-09-01T18:52:21.422Z</atom:updated>
            <content:encoded><![CDATA[<p>嗚嗚嗚，來到JS中永遠搞不懂的this了，當初在寫的時候好痛苦，完全不～理～解為什麼要加this.xxxx在前面啊！讓我們繼續看下去。</p><blockquote>只要parameter跟class裡的variable一樣，就可以加上this-&gt;來指派該variable，如下面示例。</blockquote><pre>#include &lt;iostream&gt;</pre><pre>using namespace std;</pre><pre><br>class Student {</pre><pre>private:</pre><pre>    string name; // this-&gt;指的是這裡declare的string name和int age</pre><pre>    int age;</pre><pre>public:</pre><pre>    Student(string n, int a){ // 只要parameter跟class裡的variable一樣</pre><pre>       this-&gt; name = n; //表示這個name指的是class Student的string name</pre><pre>       this-&gt; age = a; //表示這個age指的是class Student的int age<br>    }</pre><pre>    void display(){</pre><pre>       cout &lt;&lt; &quot;Name: &quot; &lt;&lt; name &lt;&lt; endl;</pre><pre>       cout &lt;&lt; &quot;Age: &quot; &lt;&lt; age &lt;&lt; endl;<br>    }</pre><pre>};</pre><pre>int main() {</pre><pre>    Student s1(&quot;Long&quot;, 24);</pre><pre>    Student s2(&quot;Kien&quot;, 29);</pre><pre>    s1.display();</pre><pre>    s2.display();</pre><pre>    return 0;</pre><pre>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e3c75d9fa84" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[private & public差在哪兒呢？新手村之C++物件導向]]></title>
            <link>https://medium.com/@happyirenehu/private-public%E5%B7%AE%E5%9C%A8%E5%93%AA%E5%85%92%E5%91%A2-%E6%96%B0%E6%89%8B%E6%9D%91%E4%B9%8Bc-%E7%89%A9%E4%BB%B6%E5%B0%8E%E5%90%91-c2448047ac3d?source=rss-4cf426519472------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2448047ac3d</guid>
            <dc:creator><![CDATA[Irene H]]></dc:creator>
            <pubDate>Thu, 01 Sep 2022 18:26:05 GMT</pubDate>
            <atom:updated>2022-09-01T18:26:05.917Z</atom:updated>
            <content:encoded><![CDATA[<p>來看看object-oriented programming的第一個關主～</p><p><em>前言：從javascript那邊過來C++的心得就是，之前似懂非懂的資料觀念在C++這邊清晰許多，當時寫了this其實還是不太懂到底為什麼要這樣用。也不知道原來那就是object-oriented誤打誤撞的拷貝貼上修改。</em></p><p>簡而言之，物件導向是把variable和function包在一個的方式，最一開始單行的hello world!，在main裡面晃而已</p><pre>main(){<br> std::cout &lt;&lt; &quot;Hello world!&quot;;<br>};</pre><p>隨著功能越來越多，我們的程式越來越長，可能會變成這樣</p><pre>main(){<br>  int num = 5;<br>  int num2 = 7; <br>  int sum;<br>  sum = num + num2;<br>  std::cout &lt;&lt; sum; // output 12</pre><p>變成出現function，可以把方法包在function裡面</p><pre>void function sum(int num1, int num2){<br>   int sum;<br>   sum = num1 + num2;<br>   return sum;<br>}<br>main(){<br>   sum(3,6);<br>   std::cout &lt;&lt; sum; // output 9</pre><p>到越來越複雜，超級多不同的function各自都有自己的variable，一不小心可能就呼叫到別人的，不好管理加上一長串的字要滑很久，也不方便找東西，所以就出現了struct和class。</p><p>Struct只能定義variable，class是連variable和function都能包在一起，以房子來舉例，struct像是share house，臥室(variable)是私有的但客廳廚房廁所是公用的，class是一間studio，在私人空間裡可以愛怎麼擺就怎麼放，不怕會跟別人打在一起。</p><p>那這篇文章主要說如何區別public和private，public就是指studio裡面哪些東西是放在門口（例如鞋櫃、腳踏墊、椅子、擺飾），鄰居經過的都能拿走（如果要偷的話），private指的是鎖在房間保險櫃裡外人拿不到的區域。</p><blockquote>注意：如果沒有在前面定義範圍的話，會自動被認定是private喔</blockquote><pre>class Class_name{<br>    int num = 4; //默認都是private<br>}<br>main (){ <br>    ....<br>}</pre><blockquote>1. private 和public有什麼差別？</blockquote><blockquote>private只有在自己的框框裡可以用</blockquote><pre>class class_name{</pre><pre>     int num = 5; //這框框裡面可以用</pre><pre>}; //到這邊為止</pre><pre>class class_name2 {<br>     int sum;</pre><pre>     //這裡就不能呼叫<br>    void myFunc(){<br>     sum = num + 1; //不能呼叫上面的num＝5<br>    }<br>};</pre><blockquote>public是可以在別的class或是main裡面也可以取用</blockquote><pre>class class_name {<br>   private:<br>   // 只在這個class裡面才能使用</pre><pre>   public:<br>   // 樓下的class_name2跟main都可以取用</pre><pre>};<br>class class_name2{</pre><pre>}<br>main {</pre><pre>}    </pre><p>還有一個叫做protected的權限，這個靜待下回分解，因為會聊到另個觀念，friend。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2448047ac3d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[30 Days of Code—Day 1 & Day 2: stdin input, 2D array]]></title>
            <link>https://medium.com/@happyirenehu/30-days-of-code-day-1-day-2-stdin-input-2d-array-cd83d75fbd8b?source=rss-4cf426519472------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd83d75fbd8b</guid>
            <dc:creator><![CDATA[Irene H]]></dc:creator>
            <pubDate>Thu, 25 Aug 2022 04:30:24 GMT</pubDate>
            <atom:updated>2022-08-25T04:30:24.760Z</atom:updated>
            <content:encoded><![CDATA[<p>在玩HackRank Day 1 challenge時發現 ，誒等一下</p><pre>string one = &quot;I love popcorn!&quot;;<br>std::cout &gt;&gt; one; //出來只剩下 I...</pre><p>額，來請出Google大神，原來空格鍵會被當成是delimiter，所以自動停掉，但我後面還有字啊</p><pre>getline(cin, string_name);</pre><p>然後原來要印出1.0這種數字必須要這樣。setprecision(定義有幾個decimal)，fixed就是讓這個位置不要有變動。所以input是1.0，這樣就會繼續印出1.0。一般來說後面零會直接被刪除。</p><pre>cout &lt;&lt;setprecision(1) &lt;&lt; fixed&lt;&lt;d+d2&lt;&lt;endl;</pre><p>抄一下外網對fixed的解釋：</p><blockquote>当然，fixed 操作符可能最重要的还是当它与 setprecision 操作符一起使用时，setprecision 即可以以一种新的方式显示。它将指定浮点数字的小数点后要显示的位数，而不是要显示的总有效数位数。而这通常正是我们想要的。</blockquote><p>Day 2 challenge 很簡單，主要的卡關在計算percent的時候會出現小數點，如稅金跟小費是百分比來算的，例如食物56元 ＊ 小費20%=11.2，故不能用int來裝小費，要用double。</p><p>另外就是perameter的數字是固定了，在題目裡給的是這樣</p><pre><strong>void</strong> solve(<strong>double</strong> meal_cost, <strong>int</strong> tip_percent, <strong>int</strong> tax_percent){ <br>        <br>}</pre><pre>main(){<br><strong>solve(12, 20, 8);<br>}</strong></pre><blockquote>因此計算時不能直接帶入餐費乘以小費，這樣會變成餐費乘以20(56乘以20?!)，要先把餐費除以100再乘以20才會得出原本20%的小費。56/100=0.56，0.56*20=11.2</blockquote><p>另外重點觀念複習，void function是不能return出東西的，但最後一行要加return;</p><p>要輸出vector就用std::vector function_name()，int 就用int function_name()依此類推，不是vector就無法輸出vector喔！這是定義好的無法變更。</p><p>LeetCode easy刷題之新手包第二題 1672. Richest Customer Wealth，沒碰過2D array先自己試玩了一下：</p><pre>#include &lt;iostream&gt;</pre><pre>using namespace std;</pre><pre>int main()<br>{<br>     int arr[2][4] ={ //first[2]is number of array, second[4] is the size of the array<br>        {1,1,3,4},<br>        {4,3,2,1}    <br>    };<br>    <br>    int i, j = 0;<br>    int num_elements=0;<br>    float sum1, sum2, sum3, sum4;<br>    int number_of_rows = 2; //m<br>    int columns =4; //n</pre><pre>for(i = 0; i &lt; number_of_rows; i++){ // sum of all numbers<br>        for(j = 0; j &lt; number_of_columns; j++){<br>            sum1+=arr[i][j];<br>        }<br>    }<br>    <br>    for(i = 0; i &lt; 1; ++i){ // sum of first rows<br>            for(j = 0; j &lt; number_of_columns; ++j){<br>                sum2+=arr[i][j];<br>            }<br>        }<br>        <br>    for(i = 0; i =2 ; ++i){ // sum of second rows<br>            for(j = 0; j &lt; number_of_columns; ++j){<br>                sum2+=arr[i][j];<br>            }<br>        }     <br>    cout &lt;&lt; &quot;The sum of all numbers: &quot; &lt;&lt; sum1&lt;&lt;&quot;\n&quot;;    <br>    cout &lt;&lt; &quot;The sum of first rows: &quot; &lt;&lt; sum2&lt;&lt; &quot;\n&quot;;<br>    cout &lt;&lt; &quot;The sum of second rows: &quot; &lt;&lt; sum3&lt;&lt;&quot;\n&quot;;<br>    cout &lt;&lt; &quot;The sum of first columns: &quot; &lt;&lt; sum4;</pre><pre>return 0;</pre><pre>}</pre><pre>console:<br>//The sum of all numbers: 15<br>//The sum of first rows: 7<br>//The sum of second rows: 8<br>//The bigger one: 8</pre><pre>來到LC想說應該能馬上解決，結果一直bug，弄了快兩個小時，結果發現是愚蠢的sytax問題，第一格class Solution { &lt;-最底部少包一個 QQ</pre><pre>int maximumWealth(vector&lt;vector&lt;int&gt;&gt;&amp; accounts) <br>{<br>    int res = 0;<br>    int m = accounts.size();<br>    int n = accounts[0].size();<br>    <br>    for(int i = 0; i &lt; m; i++)<br>    {<br>        int price = 0;<br>        for(int j = 0; j &lt; n; j++)<br>            price += accounts[i][j];<br>        <br>        res = max(res, price);<br>    }<br>    <br>    return res;<br>}</pre><pre>My solution:<br>int maximumWealth(vector&lt;vector&lt;int&gt;&gt;&amp; accounts) {<br>        int number_of_rows = accounts.size();<br>        int number_of_columns = accounts[0].size();<br>        int maxie;<br>        for(int i = 0; i &lt; number_of_rows ; ++i){<br>           int sum = 0;<br>            for(int j = 0; j &lt; number_of_columns; ++j){<br>                sum = sum + accounts[i][j];<br>            }<br>            maxie = max(maxie, sum);<br>        }<br>    return maxie;<br>    }</pre><blockquote>小撇步: 要是想取出array裏的max，需要用std::max_element。</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd83d75fbd8b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>