# kekwait

Sep 23rd, 2020
685
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <iostream>
2. #include <bits/stdc++.h>
3. #include <string>
4.
5. using namespace std;
6.
7. #define UP_ (-1)
8. #define DOWN_ (1)
9. #define LEFT_ (-1)
10. #define RIGHT_ (1)
11.
12. typedef vector< vector<int> > matrix;
13.
14. static int n;
15. static int answ_end = 0;
16.
17. inline bool limiter(int *cp) {
18.     if (!((0 <= cp[0]) && (cp[0] < n)) || !((0 <= cp[1]) && (cp[1] < n)))
19.         return false;
20.     return true;
21. }
22.
23. bool move_hor(int dir, int amount, int *cp, const matrix &src, vector<int> &answ) {
24.     for (int i = 0; i < amount; ++i) {
25.         cp[1] += dir;
26.         if (!limiter(cp))
27.             return false;
28.
29.         answ[answ_end++] = src[cp[0]][cp[1]];
30.     }
31.     return true;
32. }
33.
34. bool move_ver(int dir, int amount, int *cp, const matrix &src, vector<int> &answ) {
35.     for (int i = 0; i < amount; ++i) {
36.         cp[0] += dir;
37.         if (!limiter(cp))
38.             return false;
39.
40.         answ[answ_end++] = src[cp[0]][cp[1]];
41.     }
42.     return true;
43. }
44.
45. int main(int argc, char** argv) {
46.     scanf("%d", &n);
47.
48.     matrix mtx(n, vector<int>(n));
49.     vector<int> answ(n*n);
50.
51.     for (int i = 0; i < n; ++i)
52.         for (int j = 0; j < n; ++j)
53.             scanf("%d", &mtx[i][j]);
54.
55.     int curr_pos[] = {n/2, n/2};
56.     answ[answ_end++] = mtx[n/2][n/2];
57.
58.     int curr_ln = 1;
59.     while (true) {
60.         if (move_ver(UP_, curr_ln, curr_pos, mtx, answ)) {
61.             move_hor(RIGHT_, curr_ln, curr_pos, mtx, answ);
62.             ++curr_ln;
63.
64.             move_ver(DOWN_, curr_ln, curr_pos, mtx, answ);
65.             move_hor(LEFT_, curr_ln, curr_pos, mtx, answ);
66.             ++curr_ln;
67.         } else {
68.             break;
69.         }
70.     }
71.
72.     for (int i = 0; i < n*n; ++i) {
73.         printf("%d\n", answ[i]);
74.     }
75.
76.
77.
78.     return 0;
79. }
RAW Paste Data