02: ranks with diagonal grid

Total time limit: 1000ms memory limit: 65536kB
described
input three natural number N, i, j (1 < = i <= N, 1 <= j <= N), the output in a N * N lattice chessboard (ranks are numbering begins at 1), the grid (i, j) counterparts, the same column, grid position all the same diagonal.

As: n = 4, i = 2, j = 3 shows the grid of the second row in the third column of the board, as shown below:

first row

The second column

The third column

The fourth column

first row

(2,3)

second line

The third row

Fourth row

When n = 4, i = 2, j = 3, the resulting output is:

(2,1) (2,2) (2,3) (2,4) on the same row of the grid positions

(1,3) (2,3) (3,3) (4,3) on the same column position of the grid

Position (1,2) (2,3) (3,4) on the upper left to lower right diagonal lattice

(4,1) (3,2) (2,3) (1,4) on the bottom left to the upper right position of the diagonal grid

Input
line, three natural number N, i, j, separated by a single space between two adjacent numbers. 1 <= N <= 10.
Output
four rows:
the first row: left to right in the same row output a lattice position;
Second row: column from top to bottom in the same output position lattice;
Third row: left to bottom right diagonal line in the same output position lattice;
first four lines: output the same diagonal from the lower left to the upper right grid position.

Wherein each grid location with the format of the output is as follows: (x, y), x is the row number, y is a column number, in English punctuation, with no spaces.
Separated by a single space between adjacent two lattice positions.
Sample input
423
sample output
(2,1) (2,2) (2,3) (2,4)
(1,3) (2,3) (3,3) (4,3)
( 1,2) (2,3) (3,4)
(4,1) (3,2) (2,3) (1,4)
source
NOIP1996 universal set of second title rematch

#include<iostream>
using namespace std;
int main(){
	int N,i,j;
	cin>>N>>i>>j;
	
	for(int x=1;x<=N;x++){                   //输出行 
		cout<<'('<<i<<','<<x<<')'<<' ';
	} 
	cout<<endl;
	
	for(int y=1;y<=N;y++){                   //输出列 
		cout<<'('<<y<<','<<j<<')'<<' ';
	}
	cout<<endl;
	
	int x=i;                                 //输出左上到右下 
	int y=j;
	while(x>1&&y>1){
		x--;
		y--;
	}                                        //此时,行数或者列数有一个为1,该位置为左上角 
	for(;x<=N&&y<=N;x++){
		cout<<'('<<x<<','<<y<<')'<<' ';
		y++;
	}
	cout<<endl;
	
	
	x=i;                                     //输出左下到右上 
	y=j;
	while(x<N&&y>1){
		x++;
		y--;
	}                                        //此时,行数为n或者列数为1,该位置为左下角
	for(;x>=1&&y<=N;x--){
		cout<<'('<<x<<','<<y<<')'<<' ';
		y++;
	}
	
	return 0;
}
Published 36 original articles · won praise 0 · Views 357

Guess you like

Origin blog.csdn.net/weixin_44437496/article/details/103980489