forked from vijay532/CompetitiveSources
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpiralMatrix
More file actions
60 lines (59 loc) · 909 Bytes
/
SpiralMatrix
File metadata and controls
60 lines (59 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<bits/stdc++.h>
using namespace std;
/*int se;
int a[10001];
int b_search(int start,int end, int se)
{
int mid=(start+end)/2;
if(se==a[mid])
{
return mid;
}
else if(a[mid]>se)
{
b_search(start,mid-1,se);
}
else
{
b_search(mid+1,end,se);
}
}*/
int a[100][100];
//int i,j;
void print(int i, int j,int n, int m)
{
if(i>=n || j>=m)
{
return;
}
for(int p=i;p<m;p++)
{
cout<<a[i][p]<<" ";
}
for(int p=j+1;p<n;p++)
{
cout<<a[p][m-1]<<" ";
}
for(int p=m-2;p>=j;p--)
{
cout<<a[n-1][p]<<" ";
}
for(int p=n-2;p>i;p--)
{
cout<<a[p][j]<<" ";
}
print(i+1,j+1,n-1,m-1);
}
int main()
{
int m,n,i,j;
cin>>n>>m;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cin>>a[i][j];
}
}
print(0,0,n,m);
}