<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                雖然這段代碼可以工作,但它本可以組織的更好。既然我們已經寫了一個原型,那么我們就處于評價其設計并改進之的有利位置了。 那現在的代碼有些什么問題呢? 1. 我們提前不知道要創建多大的距離矩陣,所以我們選擇了一個任意大的數字(50),然后創建了一個固定大小的矩陣。更好的方式是允許距離矩陣以類似Set的方式擴充,而apmatrix類的resize函數使之成為可能。 2. 矩陣中的數據沒有很好的封裝。我們不得不以城市名的集合與矩陣本身作為參數傳給processLine,這樣很不合適。再就是,因為我們沒提供執行錯誤檢查的訪問函數,所以使用距離矩陣容易出錯。有個好的想法是,將表示城市名的Set對象和表示距離的apmatrix對象組合到DistMatrix類中。 下面是DistMatrix類頭文件大概形式的一個草稿: ~~~ class DistMatrix { private: Set cities; apmatrix<int> distances; public: DistMatrix (int rows); void add (const apstring& city1, const apstring& city2, int dist); int distance (int i, int j) const; int distance (const apstring& city1, const apstring& city2) const; apstring cityName (int i) const; int numCities () const; void print (); }; ~~~ 我們可以使用這個接口來簡化main函數: ~~~ void main () { apstring line; ifstream infile ("distances"); DistMatrix distances (2); while (true) { getline (infile, line); if (infile.eof()) break; processLine (line, distances); } distances.print (); } ~~~ 也可以簡化 processLine函數: ~~~ void processLine (const apstring& line, DistMatrix& distances) { char quote = ’\"’; apvector<int> quoteIndex (4); quoteIndex[0] = line.find (quote); for (int i=1; i<4; i++) { quoteIndex[i] = find (line, quote, quoteIndex[i-1]+1); } // 將行分割為子串 int len1 = quoteIndex[1] - quoteIndex[0] - 1; apstring city1 = line.substr (quoteIndex[0]+1, len1); int len2 = quoteIndex[3] - quoteIndex[2] - 1; apstring city2 = line.substr (quoteIndex[2]+1, len2); int len3 = line.length() - quoteIndex[2] - 1; apstring distString = line.substr (quoteIndex[3]+1, len3); int distance = convertToInt (distString); // 將新數據添加到距離矩陣中 distances.add (city1, city2, distance); } ~~~ 我把實現DistMatrix類的成員函數留作練習請讀者完成。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看