fork download
  1. bool UsedInBox(int grid[N][N], int boxStartRow, int boxStartCol,int r,int c,int num)
  2. {
  3. int flag=0; //to check if the number is present or not
  4. for (int row = 0; row < 3; row++)
  5. {
  6. for (int col = 0; col < 3; col++)
  7. {
  8. if (grid[row+boxStartRow][col+boxStartCol] == num)
  9. {
  10. return true; // saying there is a num already in the box
  11. }
  12. }
  13. }
  14. r=r%N; // to find out the row num in that particular box which ranges from 0-2
  15. c=c%N; // to find the col num in that partiuclar box which ranges from 0-2
  16. int boxnum=boxStartRow/N; //to find out if it is a top most box of the grid or bottom most box or middle
  17. if(boxnum==0)
  18. {
  19. for (int row = 0; row<N; row++)
  20. {
  21. for(int col=0;col<N;col++)
  22. {
  23. if(grid[row+boxnum+N][col+boxStartCol]==num)
  24. {
  25. flag=1; //if num is present make flag 1
  26. if(r==row)// if row in the bottom box matches with the row in the top box
  27. {
  28. return false; // saying that it is valid to insert here
  29. }
  30. else //if num is present but rows do not match
  31. return true;
  32. }
  33. }
  34. }
  35. if(flag==0) //if num is not present
  36. {
  37. return false;
  38. }
  39. }
  40. else if(boxnum==N-1) //if it is a box in the last row
  41. {
  42. for (int row = 0; row<N; row++)
  43. {
  44. for(int col=0;col<N;col++)
  45. {
  46. if(grid[row+boxnum-N][col+boxnum-N]==num) //check for row of the num in the above box
  47. {
  48. flag=1;
  49. if(r==row)
  50. {
  51. return false;
  52. }
  53. else
  54. return true;
  55. }
  56. }
  57. }
  58. }
  59. else //if it is a box somewhere in between
  60. {
  61. int flag2=0,flag3=0;
  62. for (int row = 0; row<N; row++)
  63. {
  64. for(int col=0;col<N;col++)
  65. {
  66. if(grid[row+boxnum+N][col+boxStartCol]==num) //check for the bottom box
  67. {
  68. flag=1;
  69. if(r==row)
  70. {
  71. flag2=1;
  72. break;
  73. }
  74. else
  75. return true;
  76. }
  77. }
  78. if(flag2==1)
  79. break;
  80. }
  81. if(flag==0)
  82. {
  83. flag2=1;
  84. }
  85.  
  86.  
  87. for (int row = 0; row<N; row++)
  88. {
  89. for(int col=0;col<N;col++)
  90. {
  91. if(grid[row+boxnum-N][col+boxnum-N]==num) //check for the top box
  92. {
  93. flag=1;
  94. if(r==row)
  95. {
  96. flag3=1;
  97. break;
  98. }
  99. else
  100. return true;
  101. }
  102. }
  103. if(flag3==1)
  104. break;
  105. }
  106. if(flag2==1 && flag3==1) //if both the top box and bottom box satisy then return false
  107. return false;
  108. }
  109. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1: error: 'N' was not declared in this scope
prog.cpp:1: error: 'N' was not declared in this scope
prog.cpp: In function 'bool UsedInBox(int, int, int, int, int)':
prog.cpp:8: error: 'grid' was not declared in this scope
prog.cpp:14: error: 'N' was not declared in this scope
prog.cpp:23: error: 'grid' was not declared in this scope
prog.cpp:46: error: 'grid' was not declared in this scope
prog.cpp:66: error: 'grid' was not declared in this scope
prog.cpp:91: error: 'grid' was not declared in this scope
stdout
Standard output is empty