-
Notifications
You must be signed in to change notification settings - Fork 0
/
PPATTERN.cpp
54 lines (41 loc) · 1.12 KB
/
PPATTERN.cpp
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
#include <iostream>
int main(int argc, char const *argv[])
{
int t, n;
int arr[101][101] = {0};
std::cin >> t;
for (; t > 0; t--) {
std::cin >> n;
int base_column = 0;
int base_row = 0;
int r = 0;
int c = base_column;
// 00 01 10 02 11 20 03 12 21 30
for (int i=1; i <= n*n; i++) {
// std::cout << r << "," << c << " " << i << "\n";
arr[r][c] = i;
if (c != 0 && r < n-1) {
r++;
c--;
} else {
if (base_column < n-1)
base_column++;
else
base_row++;
r = base_row;
c = base_column;
}
}
for (r = 0; r < n; r++) {
for (c = 0; c < n; c++) {
std::cout << arr[r][c];
if (c != n-1) {
std::cout << " ";
} else {
std::cout << "\n";
}
}
}
}
return 0;
}