解题思路:
注意事项:
参考代码:#include "iostream"
#include "string.h"
using namespace std;
int main()
{
int n,m;
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
int a[n][m];
for (int i = 0; i <n ; ++i) {
for (int j =0; j < m; ++j) {
cin>>a[i][j];
}
}
int i=0,j=0,num=1;
cout<<a[i][j]<<" ";
a[i][j]=-1;
while(num<n*m) {
while (a[++i][j]!=-1&&i<n){
cout<<a[i][j]<<" ";
a[i][j]=-1;
num++;
}
i--;
while (a[i][++j]!=-1&&j<m){
cout<<a[i][j]<<" ";
a[i][j]=-1;
num++;
}
j--;
while (a[--i][j]!=-1&&i>=0){
cout<<a[i][j]<<" ";
a[i][j]=-1;
num++;
}
i++;
while (a[i][--j]!=-1&&j>=0){
cout<<a[i][j]<<" ";
a[i][j]=-1;
num++;
}
j++;
}
return 0;
}
0.0分
0 人评分
计算质因子 (C++代码)浏览:1827 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:504 |
C语言程序设计教程(第三版)课后习题6.5 (C语言代码)浏览:660 |
蛇行矩阵 (C语言代码)浏览:607 |
C语言程序设计教程(第三版)课后习题9.3 (C语言代码)浏览:2121 |
愚蠢的摄影师 (C++代码)浏览:980 |
Hello, world! (C语言代码)浏览:766 |
Tom数 (C语言代码)浏览:517 |
用筛法求之N内的素数。 (C语言代码)浏览:595 |
C语言程序设计教程(第三版)课后习题8.1 (C语言代码)浏览:765 |