此代码是一个很好的解决方案,可以随机化一个二维数组并写出屏幕上所有的 符号吗?如果您有更好的提示或解决方案,请告诉我。randomise一个二维数组与字符?
int slumpnr;
srand(time(0));
char game[3][3] = {{'O','X','A'}, {'X','A','X'}, {'A','O','O'}};
for(int i = 0 ; i < 5 ; i++)
{
slumpnr = rand()%3;
if(slumpnr == 1)
{
cout << " " <<game[0][0] << " | " << game[0][1] << " | " << game[0][2] << "\n";
cout << "___|___|___\n";
}
else if(slumpnr == 0)
{
cout << " " << game[1][0] << " | " << game[1][1] << " | " << game[1][2] << "\n";
cout << "___|___|___\n";
}
else if(slumpnr == 3)
{
cout << " " << game[2][0] << " | " << game[2][1] << " | " << game[2][2] << "\n";
cout << "___|___|___\n";
}
}
system("pause");
}
[randomise a two-dimensional array?]的可能重复?(http://stackoverflow.com/questions/4003814/randomise-a-two-dimensional-array) – 2010-10-23 14:44:27
的确如此。 – 2010-10-23 14:46:17
即使用户发布了上一个问题,也是一样的。 @Nelly - 您可以编辑您以前的问题。 – 2010-10-23 14:51:52