如何在这个数独板c ++中生成数字

时间:2013-04-26 18:31:45

标签: numbers generator sudoku

我正在做一个数独谜题。我完成了董事会。但问题是我对如何在此框中生成数字感到困惑。因为它是Char的数组。但我想生成整数。我需要帮助。

这是我到目前为止所拥有的。

enter code here
#include <iostream>
#include <string>
#include <cstring>

using namespace std;


void main (){
//Descriptions and genral ideas 
cout << "WELCOME TO SUDOKU " << endl;
cout << endl;

cout << "RULES:    "<< endl;
cout << endl;

cout << "->You'll be given a 9x9 board with some numbers depending on which level of difficulty you choose to play."<< endl;
cout << endl;

cout << "->You have to arrange numbers from 1 to 9 so that a number shows up once in one row, one column and in a 3x3 box." << endl;
cout << endl;

cout << "So, let's get started" << endl;

cout << endl;
cout <<endl;



char dash[9][9];
for (int array=0; array<9; array++) {
for (int array2=0; array2<9; array2++) {
    dash[array][array2]='_';
}
}
char row[9];
char column[9];
char num[81];

int length;
length=strlen(row);
//Replaces the _'s in the specified rows/columns and replaces them with the integer the    user specified. 
for (int i=0; i<length; i++) {
dash[row[i]][column[i]]=num[i];
 }

//Builds the Sudoko board and outputs the full 9x9 array.

cout << "-------------------------------------" << endl;
for (int count=0; count<3; count++) {
for (int count2=0; count2<3; count2++) {
    cout << "|_" << dash[count][count2*3] << "_|_" << dash[count][count2*3+1] << "_|_" << dash[count][count2*3+2] << "_";   
}
    cout << "|" << endl;
}
cout << "-------------------------------------" << endl;
for (int count=3; count<6; count++) {
for (int count2=0; count2<3; count2++) {
    cout << "|_" << dash[count][count2*3] << "_|_" << dash[count][count2*3+1] << "_|_" << dash[count][count2*3+2] << "_";   
}
cout << "|" << endl;
}
cout <<"-------------------------------------" << endl;
for (int count=6; count<9; count++) {
for (int count2=0; count2<3; count2++) {
    cout << "|_" << dash[count][count2*3] << "_|_" << dash[count][count2*3+1] << "_|_" << dash[count][count2*3+2] << "_";   
}
cout << "|" << endl;
}
cout << "-------------------------------------" << endl;




system("pause");
}

1 个答案:

答案 0 :(得分:0)

您可以使用随机函数生成数字,并将其翻译为“char”,只需添加48