• <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 逛奔的蝸牛 閱讀(914) 評論(0)  編輯 收藏 引用 所屬分類: C/C++
            思思久久好好热精品国产| 丁香五月综合久久激情| 久久久久久久久波多野高潮| 思思久久99热只有频精品66| 日韩精品久久无码中文字幕| 久久精品成人国产午夜| 久久久久18| 久久久久亚洲AV成人片| 久久精品中文字幕有码| 久久婷婷五月综合97色直播| 国产精品女同久久久久电影院| 久久精品国产一区二区三区不卡| 久久精品国产亚洲αv忘忧草| 国产精品九九久久免费视频| 中文字幕无码精品亚洲资源网久久| 国产精品欧美久久久天天影视| 久久成人精品| 天天综合久久久网| 久久丫精品国产亚洲av不卡| 亚洲人成无码久久电影网站| 久久青草国产手机看片福利盒子| 久久热这里只有精品在线观看| 伊人色综合久久天天| 久久精品天天中文字幕人妻| 无码国内精品久久综合88| 国产AV影片久久久久久| 久久99国产精品尤物| 亚洲色欲久久久综合网东京热| 亚洲国产综合久久天堂| 国产精品欧美亚洲韩国日本久久| 潮喷大喷水系列无码久久精品| 免费精品久久天干天干| 伊人色综合久久天天网| 久久综合亚洲色HEZYO国产| 久久久久99精品成人片| 国产精品欧美亚洲韩国日本久久 | 怡红院日本一道日本久久 | 久久久久久久久久久久中文字幕 | 精品综合久久久久久97超人| 久久久一本精品99久久精品66 | 久久久久久久久久久久中文字幕|