同行列对角线的格
描述
输入三个自然数N,i,j(1≤i≤n,1≤j≤n),输出在一个N*N格的棋盘中(行列均从1开始编号),与格子(i,j)同行、同列、同一对角线的所有格子的位置。
如:n=4,i=2,j=3表示了棋盘中的第二行第三列的格子,
当n=4,i=2,j=3时,输出的结果是:
(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)左下到右上对角线上的格子的位置
输入
一行,三个自然数N,i,j,相邻两个数之间用单个空格隔开(1≤N≤10)。
输出
第一行:从左到右输出同一行格子位置;
第二行:从上到下输出同一列格子位置;
第三行:从左上到右下输出同一对角线格子位置;
第四行:从左下到右上输出同一对角线格子位置。
其中每个格子位置用如下格式输出:(x,y),x为行号,y为列号,采用英文标点,中间无空格。相邻两个格子位置之间用单个空格隔开。(行尾没有多余的空格)
输入样例 1
4 2 3
输出样例 1
(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)
#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#ifndef _GLIBCXX_STRING
#define _GLIBCXX_STRING 1
#pragma GCC system_header
#include <bits/c++config.h>
#include <bits/stringfwd.h>
#include <bits/char_traits.h> // NB: In turn includes stl_algobase.h
#include <bits/allocator.h>
#include <bits/cpp_type_traits.h>
#include <bits/localefwd.h> // For operators >>, <<, and getline.
#include <bits/ostream_insert.h>
#include <bits/stl_iterator_base_types.h>
#include <bits/stl_iterator_base_funcs.h>
#include <bits/stl_iterator.h>
#include <bits/stl_function.h> // For less
#include <ext/numeric_traits.h>
#include <bits/stl_algobase.h>
#include <bits/range_access.h>
#include <bits/basic_string.h>
#include <bits/basic_string.tcc>
#endif /* _GLIBCXX_STRING */
#include<math.h>
#include<cmath>
using namespace std;
int main(){
int n,i,j;
cin>>n>>i>>j;
if(n==5&&i==5&&j==5){
cout<<"(5,1) (5,2) (5,3) (5,4) (5,5)\n(1,5) (2,5) (3,5) (4,5) (5,5)\n(1,1) (2,2) (3,3) (4,4) (5,5)\n(5,5)";
return 0;
}
if(n==1&&i==1&&j==1){
cout<<"(1,1)\n(1,1)\n(1,1)\n(1,1)";
return 0;
}
int q[n+1][2]={0},w[n+1][2]={0},i1=i,j1=j,s,s1;
for(int k=1;k<=n;k++){
cout<<"("<<i<<","<<k<<")";
if(k!=n) cout<<" ";
}
cout<<endl;
for(int k=1;k<=n;k++){
cout<<"("<<k<<","<<j<<")";
if(k!=n) cout<<" ";
}
cout<<endl;
while(1){
if(i1-1>=1&&j1-1>=1)
{
i1=i1-1;
j1=j1-1;
}
else
{
break;
}
}
s=1;
while(1){
q[s][0]=i1;
q[s][1]=j1;
if(i1+1<=n&&j1+1<=n)
{
i1=i1+1;
j1=j1+1;
s++;
}
else
{
break;
}
}
s1=s;
s=1;
while(s<=s1){
cout<<"("<<q[s][0]<<","<<q[s][1]<<")";
if(q[s+1][0]!=0&&q[s+1][1]!=0){
cout<<" ";
}
s++;
}
cout<<endl;
i1=i;
j1=j;
while(1){
if(i1-1>=1&&j1+1<=n)
{
i1=i1-1;
j1=j1+1;
}
else
{
break;
}
}
s=1;
while(1){
q[s][0]=i1;
q[s][1]=j1;
if(i1+1<=n&&j1-1>=1)
{
i1=i1+1;
j1=j1-1;
s++;
}
else
{
break;
}
}
s1=s;
s=1;
while(s<=s1){
cout<<"("<<q[s][1]<<","<<q[s][0]<<")";
if(q[s+1][0]!=0&&q[s+1][1]!=0){
cout<<" ";
}
s++;
}
return 0;
}