23: Two-dimensional array loopback traversal
- View
- Submit
- Statistics
- Questions
-
Total time limit:
-
1000ms
-
Memory Limit:
-
65536kB
-
Describe
-
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. :
-
Input
-
The first line of input has two integers, row and col, in turn.
The remaining row rows, each containing a col integer, form a two-dimensional array of integers.
(Note: The input row and col guarantees 0 < row < 0 < col < 100)
-
Output
-
Each integer is output in the traversal order. Each integer occupies one row.
-
Sample input
-
4 41 2 3 412 13 14 511 16 15 610 9 8 7
-
Sample output
-
12345678910111213141516
-
Source
-
2009 years of medical practice at Peking University
- View
- Submit
- Statistics
- Questions
1#include <iostream>2#include <cstdio>3#include <cstdio>4#include <cstring>5 using namespacestd;6 inta[ -][ -];7 intb[ -][ -];8 intMain ()9 {Ten intm,n,i,j; OneCin>>m>>N; A for(i=1; i<=m;i++) - { - for(j=1; j<=n;j++) the { -Cin>>A[i][j]; - } - } + for(intq=1; q<=n/2+1; q++) - { + for(i=q;i<=m-q+1; i++) A { at for(j=q;j<=n-q+1; j + +) - { - if(i==q| | j==n-q+1) - { -cout<<a[i][j]<<Endl; -b[i][j]=1; in } - } to } + for(i=m-q+1; i>=q;i--) - { the for(j=n-q+1; j>=q;j--) * { $ if((i==m-q+1|| J==Q) &&b[i][j]==0)Panax Notoginseng { -cout<<a[i][j]<<Endl; the } + } A } the } +}
23: Two-dimensional array loopback traversal