Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/133.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在数独2D数组中获取单元格的区域?_C++_Sudoku - Fatal编程技术网

C++ 如何在数独2D数组中获取单元格的区域?

C++ 如何在数独2D数组中获取单元格的区域?,c++,sudoku,C++,Sudoku,我做了一个9行9列的板,用来做数独游戏。 我试图获取传递给方法Getpossiblevalues的任何单元格的行、列和区域 我制作了数组值,它从文本文件读取并添加到每个单元格。但我没有在这里显示该代码。目前我只能通过每次检查行号和列号来完成,比如检查行=0,行=1等等 int main(){ board[9][9]; //creates a 9*9 matrix or a 2d array. for(int i=0; i<9; i++) //This loops on the r

我做了一个9行9列的板,用来做数独游戏。 我试图获取传递给方法Getpossiblevalues的任何单元格的行、列和区域

我制作了数组值,它从文本文件读取并添加到每个单元格。但我没有在这里显示该代码。目前我只能通过每次检查行号和列号来完成,比如检查行=0,行=1等等

int main(){
board[9][9]; //creates a 9*9 matrix or a 2d array.


for(int i=0; i<9; i++)    //This loops on the rows.
{
    for(int j=0; j<9; j++) //This loops on the columns
    {
        cout << board[i][j]  << "  ";
    }
    cout << endl;
}
 getPossiblevalues(0,0);




int getPossiblevalues(int row, int col) {

set<int> d;
set<int> e;


//Get Rows
for (int j = 0; j < 9; j++) {
    d.insert(board[row][j]);
}

//Get Columns
for (int k = 0; k < 9; ++k) {

    d.insert(board[k][col]);
}

//Get Region
if((row == 0)|| (row ==1)||(row ==2) && ((col == 1)|| (col ==2) ||(col ==3)){

    for (int i = 0; i < 3; ++i) {

        for (int j = 0; j < 3; ++j) {

            d.insert(board[i][j]);
        }

    }
}




    for (auto i : d){

    cout <<i<<" ";
}

}

在这里询问之前,您至少应该试一试。@roeland检查编辑。我可以得到区域,但我每次都检查行号。只是看看是否有更简单的方法。你可以检查一个解决方案