C++ 8 By 8 Board
C++ 8 By 8 Board
我试图实现n皇后问题棋盘游戏,我有问题与棋盘我在这个displayboard函数中做错了什么?它应该实现一个8 × 8的空板对不起,我只是一个初学者
#include <iostream>
#include <limits>
using namespace std;
const int rows = 8;
const int columns =8;
int board[rows][columns] = {0,0};
void displayboard();
int main(){
displayboard();
system("pause");
}
void displayboard ()
{
cout << " 1 2 3 4 5 6 7 8" << endl;
cout << " ---------------";
for (int bRow = 0; bRow<rows; bRow++)
{
for (int bCol = 0; bCol<columns; bCol++)
if (board[bRow][bCol] == 0)
cout << " ";
else
cout << " ";
}
cout << endl;
return;
}
if (board[bRow][bCol] == 0)
cout << " ";
else
cout << " ";
? ?两者都做同样的事情!打印空白区域。此外,除了0
s之外,您还没有填充数组board[8][8]
。
您错过了每行的换行符和可能的空格。这里有一个固定的版本:(我用了一个'。'来表示一个(空)字段——因为它对人工调试更友好)
1 2 3 4 5 6 7 8
---------------
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
代码#include <iostream>
#include <limits>
using namespace std;
const int rows = 8;
const int columns =8;
int board[rows][columns] = {0,0};
void displayboard();
int main()
{
displayboard();
}
void displayboard ()
{
cout << " 1 2 3 4 5 6 7 8" << endl;
cout << " ---------------";
for (int bRow = 0; bRow<rows; bRow++)
{
cout << "n ";
for (int bCol = 0; bCol<columns; bCol++)
{
if (board[bRow][bCol] == 0)
{
cout << ".";
}
else
{
cout << ".";
}
cout << " "; // delimiter
}
}
cout << endl;
return;
}
相关文章:
- 使用模板进行堆栈实现; "name followed by :: must be a class or namespace"
- 将 std::thread by 值推送到列表中
- MATLAB to C++: csvread() not supported by MATLAB Coder
- Makefile by ocaml 和 cpp 扩展名
- C++ OpenCV Randu 函数抛出'Integer division by zero'
- 从函数 BY VALUE 返回数组,返回结构时会发生什么?
- 如何在不受其他文件影响的情况下"by itself" Visual Studio 项目中运行C++文件?
- MacPorts:"Error: clang-4.0 has been replaced by clang-8.0; please install that instead",但我已经安装了clang
- 为什么 c++ 向量没有"delete by index"?
- 这个给定的代码应该将给定的数字转换为尽可能滞后的数字,no.by 用 9.It 替换合适的数字是行不通的
- 传递类 by-value 时,调用方或被调用方是否调用析构函数
- By-ref 参数:这是 std::thread 和 std::bind 之间的不一致吗?
- 转到特定页面后,如何将滑动视图的当前索引设置为选项卡栏"by reference"的当前索引?
- base64 decode with openssl BIO block by block
- 如何在 C++ 中修复"/usr/bin/ld: warning: liblber-2.4.so.2, needed by //usr/lib/x86_64-linux-gnu/libcurl-gnu
- 由mpglib输出的"hip: Can't rewind stream by 74 bits"到底意味着什么?
- 用rvalue参考和变异模板bits bits bys blamda by
- CMake 错误:'target is not built by this project'
- 快速'group by/count' std::vector<std::u16string> 变成 std::map<u16string, int>
- C++ 8 By 8 Board