-
#include <iostream>
-
#include <cstring>
-
using namespace std;
-
int main()
-
{
-
int r,c,arr[100][100]={0};
-
bool Arr[100][100]={true};
-
cin>>r>>c;
-
for(int i=0;i<r;i++)
-
for(int o=0;o<c;o++)cin>>arr[i][o];
-
int sumn=0,d=1,x=0,y=0;
-
while(sumn<r*c)
-
{
-
cout<<arr[y][x]<<endl;
-
Arr[y][x]=false;
-
if(((x+1==c||Arr[y][x+1]==false)&&d==1)||((y+1==r||Arr[y+1][x]==false)&&d==2)){
-
if(d==1)d=2;
-
else if(d==2)d=3;
-
}
-
else if(((x==0||Arr[y][x-1]==false)&&d==3)||((y==0||Arr[y-1][x]==false)&&d==4)){
-
if(d==3)d=4;
-
else if(d==4)d=1;
-
}
-
if(d==1)x++;
-
else if(d==2)y++;
-
else if(d==3)x--;
-
else if(d==4)y--;
-
sumn++;
-
}
-
return 0;
-
}
08-14
1167
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-17
174
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-14
614
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)