2014-05-06 01:40

题目链接

原题:

Give a N*N matrix, print it out diagonally.
Follow up, if it is a M*N matrix, how to print it out.
Example: print:

题目:按照题目示例给出的方式,输出一个矩阵。

解法:按题意写代码即可。

代码:

 // http://www.careercup.com/question?id=5661939564806144
#include <cstdio>
#include <vector>
using namespace std; class Solution {
public:
void printDiagonal(vector<vector<int> > &matrix) {
int n, m; n = (int)matrix.size();
if (n == ) {
return;
}
m = (int)matrix[].size();
if (m == ) {
return;
} int i, j;
bool first; for (i = ; i < n + m; ++i) {
first = true;
for (j = (i < m ? i : m - ); j >= ; --j) {
if (i - j < || i - j > n - ) {
break;
}
printf((first ? "%d" : " %d"), matrix[i - j][j]);
first = false;
}
printf("\n");
}
};
};

Careercup - Google面试题 - 5661939564806144的更多相关文章

  1. Careercup - Google面试题 - 5732809947742208

    2014-05-03 22:10 题目链接 原题: Given a dictionary, and a list of letters ( or consider as a string), find ...

  2. Careercup - Google面试题 - 5085331422445568

    2014-05-08 23:45 题目链接 原题: How would you use Dijkstra's algorithm to solve travel salesman problem, w ...

  3. Careercup - Google面试题 - 4847954317803520

    2014-05-08 21:33 题目链接 原题: largest number that an int variable can fit given a memory of certain size ...

  4. Careercup - Google面试题 - 6332750214725632

    2014-05-06 10:18 题目链接 原题: Given a ,) (,) (,), (,) should be returned. Some suggest to use Interval T ...

  5. Careercup - Google面试题 - 5634470967246848

    2014-05-06 07:11 题目链接 原题: Find a shortest path ,) to (N,N), assume is destination, use memorization ...

  6. Careercup - Google面试题 - 5680330589601792

    2014-05-08 23:18 题目链接 原题: If you have data coming in rapid succession what is the best way of dealin ...

  7. Careercup - Google面试题 - 5424071030341632

    2014-05-08 22:55 题目链接 原题: Given a list of strings. Produce a list of the longest common suffixes. If ...

  8. Careercup - Google面试题 - 5377673471721472

    2014-05-08 22:42 题目链接 原题: How would you split a search query across multiple machines? 题目:如何把一个搜索que ...

  9. Careercup - Google面试题 - 6331648220069888

    2014-05-08 22:27 题目链接 原题: What's the tracking algorithm of nearest location to some friends that are ...

随机推荐

  1. 完成了server和client的框架设计

    界面暂且也不搞.先把框架搭建起来.

  2. .NET中的字符串你了解多少?

    字符串的特性 1.不可变性        由于字符串是不可变的的,每次修改字符串,都是创建了一个单独字符串副本(拷贝了一个字符串副本).之所以发生改变只是因为指向了一块新的地址.        ps: ...

  3. eclipse自动补全

    最简单的修改方式是:Windows——>Preferences——>Java-->Editor-->Content Asist,在Auto activation trigger ...

  4. ASP.NET MVC5 入门

    参考资料<ASP.NET MVC5 高级编程>第5版 第1章 入门 1.1 ASP.NET MVC 简介 ASP.NET MVC是一种构建Web 应用程序的框架,它将一般的MVC(Mode ...

  5. 无法运行maven项目

    tomcat Server Location 选择 User Tomcat installation 设置CATALINA_HOME环境变量(tomcat start.bat启动不了)1.CATALI ...

  6. Linux下发包处理

    Linux下发包处理: 1.用top分析工具来查看哪个进程占用的CPU资源比较大  2. 通过命令来查看都是那些端口被占用了   netstat -antp | more  3.在top里面查看到的异 ...

  7. ansible的playbook组件

    playbook的核心元素: tasks: 任务 variables: 变量 templates: 模板 handlers: 处理器 roles: 角色 组织格式:YAML(被称为另外一种标记语言) ...

  8. php生成excel文件的简单方法

    生成excel文件,最简单的莫过于把数据库的数据导入到excel就行了. 生成excel 当然使用的是 phpExcel http://www.jbxue.com/tags/phpexcel.html ...

  9. 代码分享:php对二维数组进行排序

    发布:net/PHP编程  编辑:thebaby   2013-06-28 13:12:54  [大 中 小] 转自:http://www.jbxue.com/article/9991.html本文介 ...

  10. PHP使用phpexcel读取excel文件

    PHP读取excel文件 require("Classes/PHPExcel.php"); require("Classes/PHPExcel/IOFactory.php ...