【发布时间】:2021-06-04 17:59:42
【问题描述】:
此任务要求在棋盘 (8 x 8) 中显示可能的象棋移动,如下所示:
x = 4, y = 4
1 0 0 0 0 0 1 0,
0 1 0 0 0 1 0 0,
0 0 1 0 1 0 0 0,
0 0 0 2 0 0 0 0,
0 0 1 0 1 0 0 0,
0 1 0 0 0 1 0 0,
1 0 0 0 0 0 1 0,
0 0 0 0 0 0 0 1
#include <iostream>
using namespace std;
int main() {
int array[8][8], x , y;
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
array[i][j] = 0;
}
}
cout << "Input x coordinate: ";
cin >> x;
cout << "Input y coordinate: ";
cin >> y;
for (int i = 0; i < 8; i++)
{ // 1st diagonal
array[x + i][y + i] = 1;
array[x - i][y - i] = 1;
}
for (int i = 0; i < 8; i++)
{ // 2nd diagonal
array[x + i][y - i] = 1;
array[x - i][y + i] = 1;
}
array[x][y] = 2;
for (int i = 0; i < 8; i++) //Cout
{
for (int j = 0; j < 8; j++)
{
cout << array[i][j];
}
cout << endl;
}
return 0;
}
它似乎只适用于第一个对角线
【问题讨论】: