• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            逛奔的蝸牛

            我不聰明,但我會很努力

               ::  :: 新隨筆 ::  ::  :: 管理 ::
            輸入一個自然數N(2≤N≤9),要求輸出如下的魔方陣,即邊長為N*N,元素取值為1至N*N,1在左上角,呈順時針方向依次放置各元素。
            N
            =3時:
            1 2 3
            8 9 4
            7 6 5
            【輸入形式】
            從標準輸入讀取一個整數N。 
            【輸出形式】
            向標準輸出打印結果。輸出符合要求的方陣,每個數字占5個字符寬度,向右對齊,在每一行末均輸出一個回車符。
            【輸入樣例】 
            4
            【輸出樣例】
             
            1  2  3  4
            12 13 14  5
            11 16 15  6
            10  9  8  7  
            #include <iostream>

            void fantasy(const int n) {
                
            int array[n][n];
                
            int topLeft[2= { 00 };
                
            int topRight[2= { 0, n - 1 };
                
            int bottomRight[2= { n - 1, n - 1 };
                
            int bottomLeft[2= { n - 10 };

                
            int row, col;
                
            int counter = 0;
                
            while (true) {
                    
            // Go right.
                    row = topLeft[0];
                    col 
            = topLeft[1];
                    
            while (col <= topRight[1]) {
                        array[row][col
            ++= ++counter;
                    }
                    topRight[
            0+= 1;
                    topRight[
            1-= 1;

                    
            // Go down.
                    row = topRight[0];
                    col 
            = topRight[1+ 1;
                    
            while (row <= bottomRight[0]) {
                        array[row
            ++][col] = ++counter;
                    }
                    bottomRight[
            0-= 1;
                    bottomRight[
            1-= 1;

                    
            // Go left.
                    row = bottomRight[0+ 1;
                    col 
            = bottomRight[1];
                    
            while (col >= bottomLeft[1]) {
                        array[row][col
            --= ++counter;
                    }
                    bottomLeft[
            0-= 1;
                    bottomLeft[
            1+= 1;

                    
            // Go up.
                    row = bottomLeft[0];
                    col 
            = bottomLeft[1- 1;
                    
            while (row > topLeft[0]) {
                        array[row
            --][col] = ++counter;
                    }
                    topLeft[
            0+= 1;
                    topLeft[
            1+= 1;

                    
            // End ?
                    if (topLeft[1>= topRight[1]) {
                        
            if (n % 2 != 0) {
                            array[n 
            / 2][n / 2= ++counter;
                        }
                        
            break;
                    }
                }

                
            // Output the result.
                for (int row = 0; row < n; ++row) {
                    
            for (int col = 0; col < n; ++col) {
                        std::cout 
            << array[row][col] << "\t";
                    }
                    std::cout 
            << std::endl;
                }
            }

            int main() {
                
            for (int i = 2; i <= 9++i) {
                    fantasy(i);
                    std::cout 
            << std::endl;
                }

                
            return 0;
            }
            聯珠頂真的回文詩:
            鶯啼岸柳
               月明弄
               夜睛春

            鶯啼岸柳弄春睛
            柳弄春睛夜月明
            明月夜睛春弄柳
            睛春弄柳岸啼鶯

            posted on 2008-04-22 15:06 逛奔的蝸牛 閱讀(912) 評論(0)  編輯 收藏 引用 所屬分類: C/C++
            国产精品毛片久久久久久久| 久久国产色av免费看| 精品久久一区二区| 91精品国产91久久久久久| 精品久久综合1区2区3区激情| 久久精品国产亚洲Aⅴ香蕉| 欧美亚洲国产精品久久| 国产精品一久久香蕉产线看| 久久久久国产成人精品亚洲午夜| 久久国产色av免费看| 国产激情久久久久影院老熟女免费| 亚洲?V乱码久久精品蜜桃 | 久久久久人妻精品一区三寸蜜桃| 日批日出水久久亚洲精品tv| 国产精品久久久久影视不卡| 青青草国产97免久久费观看| 精品一区二区久久久久久久网站| 亚洲成av人片不卡无码久久| 精品国产福利久久久| 亚洲精品乱码久久久久久自慰| 日韩欧美亚洲综合久久影院d3| 精品国产99久久久久久麻豆 | 亚洲人成网亚洲欧洲无码久久 | 久久精品午夜一区二区福利| 久久久久一本毛久久久| 2020久久精品国产免费| 久久久精品2019免费观看| 国产成人综合久久精品红| 久久婷婷五月综合成人D啪| 91精品国产高清久久久久久91| 精品久久久噜噜噜久久久| 综合久久国产九一剧情麻豆 | 亚洲日韩欧美一区久久久久我| 国产精品青草久久久久福利99| 老司机国内精品久久久久| 精品久久久久久亚洲精品| 久久精品国产亚洲AV香蕉| 亚洲日韩中文无码久久| 久久精品人人做人人爽电影蜜月| 久久午夜无码鲁丝片秋霞| 人妻丰满AV无码久久不卡|