A two-dimensional array return traversal

Source: Internet
Author: User
Total time limit: 1000ms memory limit: 65536kB description

Given an integer array of row row col columns, requires starting from the array[0][0] element, and pressing the back shape to traverse the entire array in a clockwise order from outward. As shown in the figure:


The first line of the input input has two integers, followed by row and Col.
The remaining row rows, each containing a col integer, form a two-dimensional array of integers.
(Note: The input row and Col guarantee 0 < row < 0 < col < 100) output output each integer in the traversal order. Each integer occupies one row. Sample input

4 4
1 2 3 4,
5,
6 10, 9 8
7
Sample output
1
2
3
4
5
6
7
8
9
Ten
-
15
16

#include
int main ()
{

     int n,m,i,j,t=1,x=0,y=0;
     int a[100][100],b[100][100]={0};
     scanf ("%d%d", &n,&m);
     for (i=0;i=0&&!b[x][y-1])//by row from right to left
        {
             b[x][y--]=t++;
             printf ("%d\n", A[x][y]);

        }
        while (X-1>=0&&!b[x-1][y])//By column from bottom to top traversal
        {        b[x--][y]=t++;
               printf ("%d\n", A[x][y]);

        }
    }
    return 0;

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.