fork(3) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool s[50][50];
  5.  
  6. int main() {
  7. int n;
  8. cin >> n;
  9. for(int i=0; i<n; i++)
  10. {
  11. s[0][i]=1;
  12. s[n-1][i]=1;
  13. s[i][n-1]=1;
  14. }
  15. int h=n-2, d=n-2;
  16. int pointx=n-1, pointy=0;
  17. while(1)
  18. {
  19. for(int i=0; i<h; i++)
  20. {
  21. s[pointx-i][pointy]=1;
  22. }
  23. pointx-=h-1;
  24. h-=2;
  25. if(h<=0)
  26. break;
  27. for(int i=0; i<d; i++)
  28. {
  29. s[pointx][pointy+i]=1;
  30. }
  31. pointy+=d-1;
  32. d-=2;
  33. if(d<=0)
  34. break;
  35. for(int i=0; i<h; i++)
  36. {
  37. s[pointx+i][pointy]=1;
  38. }
  39. pointx+=h-1;
  40. h-=2;
  41. if(h<=0)
  42. break;
  43. for(int i=0; i<d; i++)
  44. {
  45. s[pointx][pointy-i]=1;
  46. }
  47. pointy-=d-1;
  48. d-=2;
  49. if(d<=0)
  50. break;
  51. }
  52. s[n/2][n/2]=0;
  53. for(int i=0; i<n; i++)
  54. {
  55. for(int j=0; j<n; j++)
  56. {
  57. cout << s[i][j];
  58. }
  59. cout << endl;
  60. }
  61. return 0;
  62. }
Success #stdin #stdout 0s 4544KB
stdin
5
stdout
11111
00001
11001
10001
11111