-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEven_Matrix.cpp
More file actions
44 lines (42 loc) · 1 KB
/
Copy pathEven_Matrix.cpp
File metadata and controls
44 lines (42 loc) · 1 KB
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
/*
* @Date : 2020-06-08 14:01:51
* @Author : Abhimanyu Kumar Maurya (aerma7309@gmail.com)
*/
#include <bits/stdc++.h>
using namespace std;
bool ib = ios_base::sync_with_stdio(0);
bool it = cin.tie(0);
signed main()
{
int t;
cin >> t;
while (t--)
{
int n, cnt = 0;
cin >> n;
vector<vector<int>> arr(n, vector<int>(n));
int cl = 0, rl = 0, ch = n, rh = n;
while (rl < rh and cl < ch)
{
for (int x = cl; x < ch; x++)
arr[rl][x] = ++cnt;
rl++;
for (int x = rl; x < rh; x++)
arr[x][ch - 1] = ++cnt;
ch--;
for (int x = ch - 1; x >= cl; x--)
arr[rh - 1][x] = ++cnt;
rh--;
for (int x = rh - 1; x >= rl; x--)
arr[x][cl] = ++cnt;
cl++;
}
for (auto &i : arr)
{
for (auto &j : i)
cout << j << " ";
cout << '\n';
}
}
return 0;
}