Advertisement
kl1nov

Untitled

Dec 10th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6. int n, m;
  7. cin » n » m;
  8. int a[n+2][m+2];
  9.  
  10. for (int i = 0; i <= n + 1; i++) {
  11. for (int j = 0; j <= m + 1; j++) {
  12. a[i][j] = -1;
  13. }
  14. }
  15. for (int i = 1; i <= n; i++) {
  16. for (int j = 1; j <= m; j++) {
  17. a[i][j] = 0;
  18. }
  19. }
  20. int num = 0, row = 1, col = 0;
  21.  
  22. while (num < n * m) {
  23. while (a[row][col + 1] == 0) {
  24. col++;
  25. num++;
  26. a[row][col] = num;
  27. }
  28. while (a[row + 1][col] == 0) {
  29. row++;
  30. num++;
  31. a[row][col] = num;
  32. }
  33. while (a[row][col - 1] == 0) {
  34. col--;
  35. num++;
  36. a[row][col] = num;
  37. }
  38. while (a[row - 1][col] == 0) {
  39. row--;
  40. num++;
  41. a[row][col] = num;
  42. }
  43. }
  44.  
  45. for (int i = 1; i <= n; i++) {
  46. for (int j = 1; j <= m; j++) {
  47. if (a[i][j] % 10 == a[i][j]) cout « " ";
  48. else if (a[i][j] % 100 == a[i][j]) cout « " ";
  49. else if (a[i][j] % 1000 == a[i][j]) cout « " ";
  50. cout « a[i][j];
  51. }
  52. cout « endl;
  53. }
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement