解题思路:
递归来做很简单
注意事项:
参考代码:
#include<iostream> using namespace std; int Count = 0; int k=0; //循环次数 void dfs(int** sz,int m,int n,int i,int j) //总长度当前位置 { if(k!=0){ cout<<sz[i][j]; i++; Count--; if(Count==0)return; else cout<<' '; } else k=1; for(int t=0;t<m-1;t++) { cout<<sz[i][j]; i++; Count--; if(Count==0)return; else cout<<' '; } for(int t=0;t<n-1;t++) { cout<<sz[i][j]; j++; Count--; if(Count==0)return; else cout<<' '; } for(int t=0;t<m-1;t++) { cout<<sz[i][j]; i--; Count--; if(Count==0)return; else cout<<' '; } for(int t=0;t<n-2;t++) { cout<<sz[i][j]; j--; Count--; if(Count==0)return; else cout<<' '; } dfs(sz,m-2,n-2,i,j); } int main() { int m,n; cin>>m>>n; Count=m*n; int **sz; sz = new int* [m]; for(int i=0;i<m;i++) sz[i] = new int [n]; for(int i=0;i<m;i++) { int j=0; for(;j<n;j++) { scanf("%d",&sz[i][j]); } } dfs(sz,m,n,0,0); //system("pause"); return 0; }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题7.1 (C语言代码)浏览:1222 |
【金明的预算方案】 (C++代码)浏览:838 |
C语言程序设计教程(第三版)课后习题6.6 (C语言代码)浏览:349 |
关于C语言变量位置的问题浏览:272 |
矩阵加法 (C语言代码)浏览:1720 |
盐水的故事 (C语言代码)浏览:1524 |
C语言程序设计教程(第三版)课后习题9.10 (C语言代码)浏览:614 |
明明的随机数 (C语言代码)浏览:953 |
简单的a+b (C语言代码)浏览:645 |
逆反的01串 (C语言代码)浏览:1436 |