- 同行列对角线的格
这道题真的要用数组吗?来个大哥讲讲如拿数组解这道题
- @ 2026-11-1 23:09:58
#include<bits/stdc++.h>
using namespace std;
int main ()
{
int n,i,j;
cin>>n>>i>>j;
bool first=true;
for(int a=1;a<=n;a++)
{
if(!first)
cout<<" ";
cout<<"("<<i<<","<<a<<")";
first=false;
}
cout<<endl;
first=true;
for(int b=1;b<=n;b++)
{
if(!first)
cout<<" ";
cout<<"("<<b<<","<<j<<")";
first=false;
}
cout<<endl;
first=true;
for(int x=1;x<=n;x++)
{
int y=x-(i-j);
if(y>=1&&y<=n)
{
if(!first)
cout<<" ";
cout<<"("<<x<<","<<y<<")";
first=false;
}
}
cout<<endl;
first=true;
for(int x=n;x>=1;x--)
{
int y=(i+j)-x;
if(y>=1&&y<=n)
{
if(!first)
cout<<" ";
cout<<"("<<x<<","<<y<<")";
first=false;
}
}
cout<<endl;
return 0;
}
0 comments
No comments so far...
Information
- ID
- 600
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 6
- Tags
- (None)
- # Submissions
- 247
- Accepted
- 76
- Uploaded By