Advertisement
haufont

Untitled

Dec 18th, 2016
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include<iostream>
  3. #include<algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int mass[113][113];
  8. bool used[113][113];
  9. int dx[4] = { 0,1,0,-1 };
  10. int dy[4] = { 1,0,-1,0 };
  11.  
  12. int main()
  13. {
  14. int n;
  15. cin >> n;
  16. int d = 0;
  17. int e = 1;
  18. int x = 1, y = 1;
  19. while (e < n * n)
  20. {
  21. used[x][y] = 1;
  22. if (0 == x + dx[d] || x + dx[d] > n || y + dy[d] == 0 || y + dy[d] > n || used[x + dx[d]][y + dy[d]])
  23. {
  24. d++; d = d % 4;
  25. }
  26. x += dx[d];
  27. y += dy[d];
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement