fork(6) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, m, mat[10][10];
  6. n = m = 8;
  7. for(int i=1; i<=n; i++) {
  8. for(int j=m; j>=1; j--) {
  9. int no[10] = {0};
  10. if(j+1 <= m) no[mat[i][j+1]] = 1;
  11. if(j+2 <= m) no[mat[i][j+2]] = 1;
  12. if(i-1 > 0) no[mat[i-1][j]] = 1;
  13. if(i-2 > 0) no[mat[i-2][j]] = 1;
  14. if(i-3 > 0) no[mat[i-3][j]] = 1;
  15. int k = 0;
  16. while( no[k] ) k ++;
  17. mat[i][j] = k;
  18. }
  19. }
  20.  
  21. for(int i=1; i<=n; i++)
  22. for(int j=1; j<=n; j++)
  23. cout << mat[i][j] << " \n"[ j == n ];
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
1 0 2 1 0 2 1 0
0 1 3 0 1 3 0 1
3 2 0 3 2 0 3 2
2 3 1 2 3 1 2 3
1 0 2 1 0 2 1 0
0 1 3 0 1 3 0 1
3 2 0 3 2 0 3 2
2 3 1 2 3 1 2 3