日期:2014-05-20  浏览次数:20659 次

求动态行转列算法

69 89 109 139 169 189
100 120 140 160 180 200

转成
69 100
89 120
109 140
139 160
169 180
189 200

------解决方案--------------------
for example
Java code
int[][] a = {
    {69,89,109,139,169,189},
    {100,120,140,160,180,200}
};

int[][] b = new int[a[0].length][a.length];
for (int i=0; i<a.length; i++) {
    for (int j=0; j<a[i].length; j++) {
        b[j][i] = a[i][j];
    }
}

for (int[] t : b) {
    System.out.println(Arrays.toString(t));
}

------解决方案--------------------
Java code


private static void test() {        
        int[] a = {69,89,109,139,169,189};
        int[] b = {100,120,140,160,180,200};
        
        for(int i=0;i<a.length;i++){
            for(int j=0;j<b.length;j++){
                if(i==j){
                    System.out.println(a[i]+" "+b[j]);
                                        break;
                }
            }
        }
    }