首页 > 其他 > 详细

matrix travers

时间:2014-10-08 07:21:54      阅读:243      评论:0      收藏:0      [点我收藏+]

Write a code to read and write a matrix in below given way. 
Note : no. indicates the sequence here. 

I/P 
1 2 3 
4 5 6 
7 8 9 

 

O/P 1

1 4 7

2 5 8

3 6 9

for(i=0;i<row;i++)
    {
        for(j=0;j<col;j++)
        {
                b[j][i]=a[i][j];
            
        }
    }

 


O/P 2
1 6 7 
2 5 8 
3 4 9

for(i=0;i<row;i++)
    {
        for(j=0;j<col;j++)
        {
            if(i%2==0)
                b[j][i]=a[i][j];
            else
                b[j][i]=a[i][col-j-1];
        }
    }

 

matrix travers

原文:http://www.cnblogs.com/leetcode/p/4010382.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!