C++의 2D 배열을 사용하여 스도쿠 격자를 맵핑하려고합니다. 2d 배열의 "덤프"와 입력을 비교하여 코드를 테스트했습니다. 배열은 9x9입니다. 문제는 처음 8 개 열이 모두 완벽하다는 것입니다. 그러나 마지막 열은 9 건 중 8 건에서 잘못된 것으로 보입니다. 왜 이것이 될 수 있을까요?2D Array와 관련된 문제
CODE :
#include <iostream>
#include <fstream>
#include <string>
int i = 0;
int j = 0;
const char test[12] = {'e', '1', '2', '3', '4', '5', '6', '7', '8', '9', '*'};
std::string abc = "";
// Class to map out a sudoku grid
class grid {
public:
char board[8][8];
void mapChars(std::string fileName) {
int x = 0;
int y = 0;
std::string line;
std::ifstream myfile (fileName.c_str());
if (myfile.is_open()) {
while (getline(myfile,line)) {
for(std::string::size_type i = 0; i < line.size(); ++i) {
if(strchr(test, line[i]) != NULL){
if (line[i] == 'e') {
y++; x=0;
} else {
board[y][x] = line[i];
x++;
}
}
}
} myfile.close();
}
}
void dumpMap() {
while(j < 9){
while(i < 9){
std::cout << board[j][i] << ' ';
++i;
}
std::cout << std::endl;
++j;
i = 0;
}
}
} sudoku;
int main() {
sudoku.mapChars("easy1.map");
sudoku.dumpMap();
std::cin >> abc;
return 0;
}
'9x9' 어레이로 스도쿠 보드를 정의해야합니까? –
"배열은 9x9"O RLY입니까? –
@ wolfPack88이 설명하기를, 나는 선언과 색인 생성 사이에 혼란 스러웠다. – Rhys