<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>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # 檢查矩陣的所有行是否都是彼此旋轉 > 原文: [https://www.geeksforgeeks.org/check-rows-matrix-circular-rotations/](https://www.geeksforgeeks.org/check-rows-matrix-circular-rotations/) 給定 n * n 大小的矩陣,任務是查找所有行是否都是彼此的圓周旋轉。 **示例**: ``` Input: mat[][] = 1, 2, 3 3, 1, 2 2, 3, 1 Output: Yes All rows are rotated permutation of each other. Input: mat[3][3] = 1, 2, 3 3, 2, 1 1, 3, 2 Output: No Explanation : As 3, 2, 1 is not a rotated or circular permutation of 1, 2, 3 ``` 這個想法是基于下面的文章。 [用于檢查字符串是否彼此旋轉的程序](https://www.geeksforgeeks.org/a-program-to-check-if-strings-are-rotations-of-each-other/) **步驟**: 1. 創建一個由第一行元素組成的字符串,并將其與自身連接在一起,以便可以高效地執行字符串搜索操作。 將此字符串設為 str_cat。 2. 遍歷所有剩余的行。 對于要遍歷的每一行,創建一個當前行元素的字符串 str_curr。 如果 str_curr 不是 str_cat 的子字符串,則返回 false。 3. 返回 true。 下面是上述步驟的實現。 ## C++ ```cpp // C++ program to check if all rows of a matrix // are rotations of each other #include <bits/stdc++.h> using namespace std; const int MAX = 1000; // Returns true if all rows of mat[0..n-1][0..n-1] // are rotations of each other. bool isPermutedMatrix( int mat[MAX][MAX], int n) { ????// Creating a string that contains elements of first ????// row. ????string str_cat = ""; ????for (int i = 0 ; i < n ; i++) ????????str_cat = str_cat + "-" + to_string(mat[0][i]); ????// Concatenating the string with itself so that ????// substring search operations can be performed on ????// this ????str_cat = str_cat + str_cat; ????// Start traversing remaining rows ????for (int i=1; i<n; i++) ????{ ????????// Store the matrix into vector in the form ????????// of strings ????????string curr_str = ""; ????????for (int j = 0 ; j < n ; j++) ????????????curr_str = curr_str + "-" + to_string(mat[i][j]); ????????// Check if the current string is present in ????????// the concatenated string or not ????????if (str_cat.find(curr_str) == string::npos) ????????????return false; ????} ????return true; } // Drivers code int main() { ????int n = 4 ; ????int mat[MAX][MAX] = {{1, 2, 3, 4}, ????????{4, 1, 2, 3}, ????????{3, 4, 1, 2}, ????????{2, 3, 4, 1} ????}; ????isPermutedMatrix(mat, n)? cout << "Yes" : ??????????????????????????????cout << "No"; ????return 0; } ```
                  <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>

                              哎呀哎呀视频在线观看