格子问题题解

Go CSP-S! · 发布于 2019-08-14 · 浏览 695 回复 0

要解决这个问题,就要搞清楚二维数组下标的规律。

#include<iostream>
using namespace std;

int main(){
int n,x,y;
cin>>n>>x>>y;
for(int i=1; i<=n; i++)

cout<<"("<<x<<","<<i<<")";
cout<<endl;
for(int i=1; i<=n; i++)

cout<<"("<<i<<","<<y<<")";
cout<<endl;
int i=x,j=y;
while (i>1 && j>1)

i--,j--;
while (i<=n && j<=n)

cout<<"("<<i++<<","<<j++<<")";
cout<<endl;
i=x,j=y;
while (i<n && j>1)

i++,j--;
while (i>=1 && j<=n)

cout<<"("<<i--<<","<<j++<<")";
cout<<endl;
return 0;
}

 

全部回复 共 0 条

还没有人回复。往下写第一条。

发表回复