1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include <iostream>
#include <cstdlib>//for the rand() function
using namespace std;
int KenKenBoard[6][6]={{0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,0,0,0}};
int GetKenKenBoard(int x, int y)
{
KenKenBoard[x][y]=rand() % 6 + 1;
for(int r=0; r<6 && r!=x; r++)
{
while(KenKenBoard[x][y]==KenKenBoard[r][y])
{
KenKenBoard[x][y]=rand() % 6 + 1;
}
}
for(int c=0; c<6 && c!=y; c++)
{
while(KenKenBoard[x][y]==KenKenBoard[x][c])
{
KenKenBoard[x][y]= rand() % 6 + 1;
}
}
}
void PrintKenKenBoard()
{
for(int x=0; x<6; x++)
{
for(int y=0; y<6; y+++
{
cout<<KenKenBoard[x][y]
}
cout<<endl;
}
}
int main()
{
for(int x=0; x<6; x++)
{
for(int y=0; y<6; y++)
{
GetKenKenBoard(x,y);
}
}
PrintKenKenBoard();
cin.get();
}
|