<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    一切皆可抽象

    大而無(wú)形 庖丁解牛 厚積薄發(fā) 滌慮玄覽
       ::  ::  ::  ::  :: 管理

    結(jié)果
    順時(shí)針

    01   02   03   04  

    10   11   12   05  

    09   08   07   06  

    逆時(shí)針

    04   03   02   01  

    05   12   11   10  

    06   07   08   09  

    代碼
    public class test {
      public test() {
      }
      private static int[][] data = null;

      private int datai = 1;    //數(shù)值
      private static int  h =0, i=0, j;
      private int row1 =0,col1 =0,row2=0,col2=0;
     
      static int x=3,y=4;    // x=? y=?

      public static void main(String[] args)
      {
         j = y-1;
         data = new int[x][y];  //data init  定義了x行 y列的矩陣 用于存放數(shù)據(jù)
         test t = new test();
         t.input(1);           //開始數(shù)據(jù)塞入 1表示 從左到右
         //數(shù)據(jù)輸出
         System.out.println("順時(shí)針");
         for (int ki=0;ki     {
           for (int kj=0;kj       {

             System.out.print(addZero(String.valueOf(x*y).length(),data[ki][kj])+"   ");
           }
           System.out.println("");
         }


         System.out.println("逆時(shí)針");
         int[][] kk = niuniu(data,x,y); //矩陣倒置
         for (int ki=0;ki     {
           for (int kj=0;kj       {

             System.out.print(addZero(String.valueOf(x*y).length(),kk[ki][kj])+"   ");
           }
           System.out.println("");
         }


      }

      private  void input(int typej)
      {
         if (datai > x*y)
         {
           //System.out.println("exit");如果數(shù)據(jù)塞入到頭 退出遞歸
         }
         else
         {


          //從左到右塞入數(shù)據(jù)
          if (typej == 1) {
             for (int k = i; k <= j; k++) {
               data[h][k] = datai++;
             }

             row1++;  //上面走了一行
             h = y - 1 - col1;  //下一步從上到下表示的列值
             i = row1;          //行起始
             j = x - 1 - col1;  //行終止
             input(2);         //從上到下遍歷數(shù)據(jù)
           }

           //從上到下塞入數(shù)據(jù)
           if ( typej == 2) {
             for (int k = i; k <= j; k++) {
                data[k][h] = datai++;
              }

             col1++;  //左邊走了一列
             h = x - 1 - row2;  //下一步從右到左表示的行值
             i = y - 1 - col1;  //列起始
             j = col2;          //列終止
             input(3);          //從右到左遍歷數(shù)據(jù)
           }

           //從右到左塞入數(shù)據(jù)
           if ( typej == 3) {
             for (int k = i; k >= j; k--) {
               data[h][k] = datai++;
             }

             row2++;  //下面走了一行
             h = col2;  //下一步從下到上表示的列值
             i = x - 1 - row2;   //行起始
             j = row1;           //行終止
             input(4);           //從下到上遍歷數(shù)據(jù)
           }

           //從下到上塞入數(shù)據(jù)
           if (typej == 4) {
             for (int k = i; k >= j; k--) {
               data[k][h] = datai++;
             }

             col2++;  //左面走了一列
             h = row1;  //下一步從左到右的行值
             i = col2;   //列起始
             j = y - 1 - col1;  //列終止
             input(1);
           }
         }
      }

        //補(bǔ)位
        public static String addZero(int weishu, int num) {
        /* int num=new Integer(num).intValue();*/
        int len = Integer.toString(num).length();
        if (len >= weishu) {
          return Integer.toString(num);
        }
        int i = 0;
        int j = weishu - len;
        String BH = "";
        while (i < j) {
          BH = "0" + BH;
          i = i + 1;
        }
        BH = BH + Integer.toString(num);
        return BH;
      }

      //列copy,第1列和最后一列互換 依次類推
      public static int[][] niuniu(int[][] temp,int xi,int yi)
      {
        int[][] rs = new int[xi][yi];
        int foxi = yi/2;
        for (int i=0;i    {
          for (int j=0;j      {
            rs[j][yi-1-i] = temp[j][i];
          }
        }
        int col = foxi-1;
        int k = 0;
        if (yi%2 == 0)
        {
          k = foxi;
        }
        else
        {
          k = foxi +1;
        }
        for (int i=k;i<=yi-1;i++)
        {
          for (int j=0;j      {
            rs[j][col] = temp[j][i];
          }
          col--;
        }

        if (yi%2 == 0)
        {
        }
        else
        {
         for (int j=0;j     {
          rs[j][foxi] = temp[j][foxi];
         }

        }

        return rs;
      }


    }


    評(píng)論

    # re: 關(guān)于一個(gè)矩陣算法  回復(fù)  更多評(píng)論   

    2005-09-05 19:46 by Pudgy's World
    這個(gè)就是螺旋虧陳矩陣吧。

    # re: 關(guān)于一個(gè)矩陣算法  回復(fù)  更多評(píng)論   

    2005-09-05 19:49 by 鋒出磨礪
    對(duì) 算法比較老土 。如果誰(shuí)有更好的 請(qǐng)貼出共同參考學(xué)習(xí)。

    # re: 關(guān)于一個(gè)矩陣算法  回復(fù)  更多評(píng)論   

    2005-09-06 11:36 by ^ Mustang ^
    我們當(dāng)初C語(yǔ)言考試的大題里有一道這樣的

    # re: 【原創(chuàng)】關(guān)于一個(gè)矩陣算法  回復(fù)  更多評(píng)論   

    2006-05-29 20:19 by 月?lián)?/a>
    class Test5{
    public static void main(String[] args){
    final int count = 10;
    int k = 1;
    int[][] a = new int[count][count];
    for (int n = 0; n<(count+1)/2; n++){ //從外往里需要(count+1)/2圈
    for (int i = n; i<count - n; i++){ //上橫行
    a[i][n] = k++;
    }
    for (int i = n + 1; i<count - n; i++){ //右豎行
    a[count-n-1][i] = k++;
    }
    for (int i = count-n-2; i>=n; i--){ //下橫行
    a[i][count-n-1] = k++;
    }
    for (int i = count-n-2; i>n; i--){ //左豎行
    a[n][i] = k++;
    }
    }
    for (int i = 0; i<count; i++){
    for (int j = 0; j<count; j++)
    System.out.print (a[i][j] + " ");
    System.out.println ();
    }
    }
    }
    我們老師寫的。
    主站蜘蛛池模板: 久久精品国产亚洲AV香蕉| 亚洲a∨无码精品色午夜| 国产精品hd免费观看| 婷婷综合缴情亚洲狠狠尤物| 亚洲综合激情另类专区| 高清免费久久午夜精品| 国产福利视精品永久免费| 久久亚洲AV成人无码| 又粗又大又黑又长的免费视频| 亚洲午夜无码片在线观看影院猛| 成人a毛片免费视频观看| 久久综合亚洲色HEZYO国产| 成在线人免费无码高潮喷水| 亚洲成色www久久网站夜月| 四虎国产成人永久精品免费| 99久久精品国产亚洲| 久久久高清免费视频| 一本色道久久88—综合亚洲精品 | 亚洲欧洲国产精品你懂的| 久久久久免费看成人影片| 亚洲中文字幕无码av在线| 免费羞羞视频网站| 日日摸夜夜添夜夜免费视频| 亚洲精品国产精品乱码不卡√| 99爱免费观看视频在线| 亚洲中文字幕无码中文| 日本亚洲国产一区二区三区| 久久99国产乱子伦精品免费| 亚洲男女内射在线播放| 免费国产在线视频| 国产亚洲sss在线播放| 国产精品免费网站| 美女被免费视频网站| 无码乱人伦一区二区亚洲| 国产免费福利体检区久久| 亚洲AV无码乱码在线观看牲色| baoyu777永久免费视频| 亚洲av无码国产综合专区| 亚洲毛片av日韩av无码| 色片在线免费观看| 精品国产呦系列在线观看免费|