仔细学习printf
by cmll02 @ 2020-08-26 11:53:05
```
#include<bits/stdc++.h>
using namespace std;
struct note{
int x;
int y;
int s;
};
note que[250000];
int main(){
int a[402][402];
bool book[450][450];
int nextx[8]={1,2,2,1,-1,-2,-2,-1};
int nexty[8]={-2,-1,1,2,2,1,-1,-2};
int startx,starty,fx,fy,m,n,head,tail,tx,ty;
cin>>n>>m>>startx>>starty;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
a[i][j]=-1;
head=1;
tail=1;
que[head].x=startx;
que[head].y=starty;
que[head].s=0;
a[startx][starty]=0;
tail++;
book[startx][starty]=1;
while(head<tail){
for(int i=0;i<8;i++){
tx=que[head].x+nextx[i];
ty=que[head].y+nexty[i];
if(tx<1||tx>n||ty<1||ty>m)
continue;
if(book[tx][ty]==0){
que[tail].x=tx;
que[tail].y=ty;
que[tail].s=que[head].s+1;
book[tx][ty]=1;
a[tx][ty]=que[tail].s;
tail++;
}
}
head++;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i][j]<0){
cout<<a[i][j]<<" ";
}
else{
cout<<a[i][j]<<" ";
}
}
cout<<endl;
}
return 0;
}
```
by ckun @ 2020-08-26 11:54:17
@[shygo_cmll02](/user/171487) cout不行么
by ckun @ 2020-08-26 11:54:47
%-5d
by a___ @ 2020-08-26 11:55:01
@[a___](/user/35137) 我试试
by ckun @ 2020-08-26 11:56:03
@[ckun](/user/254317) 可能走两位数或三位数步
by a___ @ 2020-08-26 11:56:48
```std::left```是个好东西,我们都要爱护它(
by SIXIANG32 @ 2020-08-26 11:58:36
@[ckun](/user/254317)
by SIXIANG32 @ 2020-08-26 11:58:57
谁说cout不行啦(恼
by SIXIANG32 @ 2020-08-26 11:59:14
@[SIXIANG](/user/298549) 学到了,c++万岁
by ckun @ 2020-08-26 12:01:33