循环数组打印
2016-05-20 22:04
316 查看
class Printer { public: vector<int> clockwisePrint(vector<vector<int> > mat, int n, int m) { // write code here vector<int> buf; if(mat.empty()) return buf; int st_x=0; int end_x=n-1; int st_y=0; int end_y=m-1; int i=0; int j=0; while(st_x<=end_x&&st_y<=end_y){ if(st_x==end_x){ for(;j<=end_y;j++) buf.push_back(mat[i][j]); return buf; } if(st_y==end_y){ for(;i<=end_x;i++) buf.push_back(mat[i][j]); return buf; } //第一行 for(;j<end_y;j++) buf.push_back(mat[i][j]); //第一列 for(;i<end_x;i++) buf.push_back(mat[i][j]); //第二行 for(;j>st_y;j--) buf.push_back(mat[i][j]); //第二列 for(;i>st_x;i--) buf.push_back(mat[i][j]); i++; j++; st_x++; st_y++; end_x--; end_y--; } return buf; } };
相关文章推荐
- 序列化的作用
- 爬虫xpath学习
- hdu5188zhx and contest [01背包至少li才能。。。]
- 训练3 习题15
- 喜剧者联盟观后感
- 饿了么开源项目Hermes:新颖巧妙易用的Android进程间通信IPC框架
- 转发与重定向区别
- TCP/IP协议原理与应用笔记21:路由选择的方法
- eclipse的应用技巧(一)
- 滴滴算法大赛算法解决过程(实时更新)
- Swift专题讲解十六——ARC在Swift中的应用
- 【bzoj 1042】 [HAOI2008] 硬币购物(dp+容斥原理)
- POJ 2385 Apple Catching
- 在Django中使用markdown
- 【模板】莫队算法
- Solr之搭建Solr6.0服务并从Mysql上导入数据
- 爱的方程
- 高精度模板2.0
- sql server 分组,取每组的前几行数据
- 发几张18650锂电池的放电曲线