Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Title
#include <iostream> #include <vector> using namespace std; void print(vector<vector<char>> board){ for(int i = 0; i < board.size(); i++){ for(int j = 0; j < board[i].size(); j++){ cout << board[i][j] << " "; } cout << endl; } cout << endl; } bool checkIfFilled(vector<vector<char>> board){ for(int i = 0; i < 4; i++){ for(int j = 0; j < 4; j++){ if(board[i][j] == '.') return false; } } return true; } bool checkIfInsertOkay(vector<vector<char>> board, int x, int y, char num){ for(int j = 0; j < 4; j++){ if(board[x][j] == num) return false; } for(int i = 0; i < 4; i++){ if(board[i][y] == num) return false; } if(x < 2) x = 0; else if(x < 4) x = 2; else x = 4; if(y < 2) y = 0; else if(y < 4) y = 2; else y = 4; for(int i = x; i < x+2; i++){ for(int j = y; j < y+2; j++){ if(board[i][j] == num) return false; } } return true; } bool sudokuSolveHelper(vector<vector<char>> &board){ if(checkIfFilled(board)) return true; for(int i = 0; i < 4; i++){ for(int j = 0; j < 4; j++){ if(board[i][j] == '.'){ for(int k = 1; k <= 4; k++){ char ch = '0' + k; if(checkIfInsertOkay(board, i, j, ch)){ board[i][j] = ch; bool flag = sudokuSolveHelper(board); if(flag) return true; else board[i][j] = '.'; } } return false; } } } return true; } bool sudokuSolve(vector<vector<char>> &board){ return sudokuSolveHelper(board); } int main() { vector<vector<char>> board = { {'.','.','.','4'}, {'4','.','.','1'}, {'.','3','.','2'}, {'.','4','.','3'}, }; print(board); bool flag = sudokuSolve(board); if(flag){ cout << "JAVAB MOJUD AST\n"; print(board); } else cout << "BEDUNE JAVAB\n"; return 0; }
run
|
edit
|
history
|
help
0
Ashish.txt
Title
Sum of inverse square series
Practice 3
Won rules summation 1 to 100 square namber
finitos
Backward
fucugigugug
A_03 ADAMS BASHFORTH S4
A