solve sudoku

Write a program to solve a Sudoku puzzle by filling the empty cells.
Empty cells are indicated by the character '.'
.
You may assume that there will be only one unique solution.


solve sudoku_第1张图片

A sudoku puzzle...

solve sudoku_第2张图片

...and its solution numbers marked in red.

#include 
#include 
#include 

#pragma GCC diagnostic error "-std=c++11"

using namespace std;
class Solution {
public:
    void solveSudoku(vector>& board) {
        assert(board.size()==9 && board[0].size()==9);
        if(isSolved(board)){
            return;
        } else{
            throw invalid_argument("no solution.");
        }


    }
private:
    bool judgeNums(int i,int j,vector>&board){
        int row=board.size();
        int column=board[0].size();
        //row no duplicate
        for(int k=0;k >&board){
        for(int i=0;i> vec(9,vector(9));
    for(int i=0;i<9;i++){
        for(int j=0;j<9;j++){
            vec[i][j]=board[i][j];
        }
    }

    Solution().solveSudoku(vec);
    for(int i=0;i<9;i++){
        for(int j=0;j<9;j++){
            cout<

你可能感兴趣的:(solve sudoku)