Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int a[20][20];
  4. int t,n,i,j,r,c,m=1,p,q;
  5. void fillup(int n,int f,int g)
  6. {
  7. r = f;
  8. c = g;
  9. while(c+1<=n)
  10. {
  11. c++;
  12. a[r][c] = 0;
  13. }
  14. c = g;
  15.  
  16. while(c-1>=1)
  17. {
  18. c--;
  19. a[r][c] = 0;
  20. }
  21. c = g;
  22.  
  23. while(r+1<=n)
  24. {
  25. r++;
  26. a[r][c] = 0;
  27. }
  28. r = f;
  29.  
  30. while(r-1>=1)
  31. {
  32. r--;
  33. a[r][c] = 0;
  34. }
  35. r = f;
  36.  
  37. while(c+1<=n && r+1<=n)
  38. {
  39. c++;
  40. r++;
  41. a[r][c] = 0;
  42. }
  43. c = g;
  44. r = f;
  45.  
  46. while(c-1>=1 && r-1>=1)
  47. {
  48. c--;
  49. r--;
  50. a[r][c] = 0;
  51. }
  52. c = g;
  53. r = f;
  54. }
  55. int main()
  56. {
  57. cin>>t;
  58. while(t--)
  59. {
  60. cin>>n;
  61. int a[n+1][n+1];
  62. for(i=1;i<=n;i++)
  63. {
  64. for(j=1;j<=n;j++)
  65. a[i][j] = 1;
  66. }
  67. for(j=1;j<=n;j++)
  68. {
  69. a[m][j] = 1;
  70. fillup(n,m,j);
  71.  
  72. for(p=1;p<=n;p++)
  73. {
  74. for(q=1;q<=n;q++)
  75. {
  76. if(a[p][q]==1)
  77. {
  78. fillup(n,p,q);
  79. }
  80. }
  81. }
  82. for(p=1;p<=n;p++)
  83. {
  84. for(q=1;q<=n;q++)
  85. cout<<a[p][q]<<" ";
  86. cout<<endl<<endl;
  87. }
  88. m++;
  89. for(p=1;p<=n;p++)
  90. {
  91. for(q=1;q<=n;q++)
  92. a[p][q] = 1;
  93. }
  94. }
  95. }
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement