【发布时间】:2012-03-10 13:46:29
【问题描述】:
您好,我需要帮助从 9x9 数组创建 9 个 3x3 维度的子数组。我已经看到 stackOverflow 已经提出了类似的问题,但不幸的是它是在 c++ 中。谁能指出我如何创建子数组的正确方向。
编辑:有一个相似的更改为有一个相似的
public static void Validate(final int[][] sudokuBoard)
{
int width = sudokuBoard[0].length;
int height = sudokuBoard.length;
for(int i = 0; i < width; i++)
if(!IsValidRow(sudokuBoard, i, width))
{
System.out.print("(Row)" + i + " Error Detected \n");
//Do something - The row has repetitions
}
for(int j = 0; j < height; j++)
if(!IsValidColumn(sudokuBoard, j, height))
{
System.out.print(" (Column)" + j + " Error Detected \n");
//Do something - The columns has repetitions
}
// for(int i=0; i<3; i++)
// if(!isBlock1Valid(sudokuBoard,width, height)){
// System.out.print("hi");
//}
}
static boolean isBlock1Valid(int[][] sudokuBoard, int referenceRow, int referenceColumn)
{
block1
boolean[] seen = new boolean[9];
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++){
if ( seen[sudokuBoard[referenceColumn+i][referenceRow+j]]) return false;
else ( seen[sudokuBoard[referenceColumn+i][referenceRow+j]]) = true;
}
}
return true;
}
这是我的验证类,它调用我已实现的布尔表达式。我不确定在验证中发送布尔值的参数。并考虑重新排列它,以便我发送 3x3 尺寸的块。
和 c++ 链接 Dividing a 9x9 2d array into 9 sub-grids (like in sudoku)? (C++)
【问题讨论】:
-
可以分享C++题的链接吗?
-
用我当前的代码更新了问题。并链接到 c++ 问题
-
我想知道你是否意识到数组在内存中表示为连续块,所以它都是关于索引的。
-
不,我不知道,但我确实有点理解只考虑索引的概念。
-
@Downvoter : 总是关心解释,哪里错了,哪里错了,至少让人们有机会通过分享你的智慧来改进。