Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include<iostream>
- #include<algorithm>
- using namespace std;
- int mass[113][113];
- bool used[113][113];
- int dx[4] = { 0,1,0,-1 };
- int dy[4] = { 1,0,-1,0 };
- int main()
- {
- int n;
- cin >> n;
- int d = 0;
- int e = 1;
- int x = 1, y = 1;
- while (e < n * n)
- {
- used[x][y] = 1;
- if (0 == x + dx[d] || x + dx[d] > n || y + dy[d] == 0 || y + dy[d] > n || used[x + dx[d]][y + dy[d]])
- {
- d++; d = d % 4;
- }
- x += dx[d];
- y += dy[d];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement