#include <iostream>
using namespace std;
void readAPuzzle(int grid[][9]);
bool search(int grid[][9]);
int getFreeCellList(const int grid[][9], int freeCellList[][2]);
void printGrid(const int grid[][9]);
bool isValid(int i, int j, const int grid[][9]);
bool isValid(const int grid[][9]);
int main()
{
// Read a Sudoku puzzle
int grid[9][9];
readAPuzzle(grid);
if (!isValid(grid))
cout << "Invalid input" << endl;
else if (search(grid))
{
cout << "The solution is found:" << endl;
printGrid(grid);
}
else
cout << "No solution" << endl;
return 0;
}
/** Read a Sudoku puzzle from the keyboard */
void readAPuzzle(int grid[][9])
{
// Create a Scanner
cout << "Enter a Sudoku puzzle:" << endl;
for (int i = 0; i < 9; i++)
for (int j = 0; j < 9; j++)
cin >> grid[i][j];
}
/** Obtain a list of free cells from the puzzle */
int getFreeCellList(const int grid[][9], int freeCellList[][2])
{
// 81 is the maximum number of free cells
int numberOfFreeCells = 0;
for (int i = 0; i < 9; i++)
for (int j = 0; j < 9; j++)
if (grid[i][j] == 0)
{
freeCellList[numberOfFreeCells][0] = i;
freeCellList[numberOfFreeCells][1] = j;
numberOfFreeCells++;
}
return numberOfFreeCells;
}
/** Display the values in the grid */
void printGrid(const int grid[][9])
{