提交时间:2024-02-12 14:57:36
运行 ID: 40536
#include<iostream> using namespace std; int main() { int N, i, j; int x, y; cin >> N >> i >> j; /* * 当N=4时,整个棋盘如下: * (1,1) (1,2) (1,3) (1,4) * (2,1) (2,2) (2,3) (2,4) * (3,1) (3,2) (3,3) (3,4) * (4,1) (4,2) (4,3) (4,4) * */ //同一行上格子的位置 for (x = 1; x <= N; x++) { cout << "(" << i << "," << x << ") "; } cout << endl; //同一列上格子的位置 for (y = 1; y <= N; y++) { cout << "(" << y << "," << j << ") "; } cout << endl; //左上到右下对角线上的格子的位置 for (x = i, y = j; x > 1 && y > 1; x--, y--); for (; x <= N && y <= N; x++, y++) { cout << "(" << x << "," << y << ") "; } cout << endl; //左下到右上对角线上的格子的位置 for (x = i, y = j; x <= N && y > 1; x++, y--); for (; x >= 1 && y <= N; x--, y++) { cout << "(" << x << "," << y << ") "; } cout << endl; return 0; }