解题思路:
递归来做很简单
注意事项:
参考代码:
#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.5 (C语言代码)浏览:642 |
2004年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:466 |
C语言训练-大、小写问题 (C语言代码)浏览:2356 |
简单的a+b (C语言代码)浏览:530 |
C语言程序设计教程(第三版)课后习题10.2 (C语言代码)浏览:509 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:902 |
关于C语言变量位置的问题浏览:272 |
简单的a+b (C语言代码)浏览:950 |
C语言程序设计教程(第三版)课后习题11.3 (C语言代码)浏览:643 |
C语言程序设计教程(第三版)课后习题8.1 (C语言代码)浏览:719 |