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. 一个学生分数表,用sql语句查询出各班级的前三名

    昨天去一家公司面试,被这道题难住了,哎,又失去一次好的机会. 回来 之后就再想这个问题 表结构及数据如下:

  2. docker开发_在basic image的基础上创建自定义的image

    方法一:docker commit 1. 跑一个basic image,docker新建了一个容器 root@ubuntu:/home/thm/docker/test# docker run -i - ...

  3. CentOS学习笔记--SCSI 设备热插拔

    CentOS学习笔记--SCSI 设备热插拔 处于运行中的服务器,因业务要求也许不允许重启机器,而新添加的SCSI设备(主要是硬盘)如何实现热插拔呢? 首先需要查看一下设备: #cat /proc/s ...

  4. jquery 仿手机屏幕切换界面效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. c#高效比对大量图片

    比较图片的方法 以前传统的比较方式是遍历图片中的每一个像素,然后进行比对.这样的比对在少量图片的比对上虽然效率低一点,但是也没有什么不好.但是在大量图片比对的时候,过长的反应时间和对服务器比较高的消耗 ...

  6. SVN 管理

    01. 源代码管理工具概述(PPT) ================================================================================ ...

  7. Widnows批处理异地备份数据

    @echo off@title Mysql+fileBckupset files=D:\backup\%date:~0,10%.rarset userdb="root"set pw ...

  8. Silverlight取得Session

    首先Session是运行在服务器上的,而Silverlight运行在客户端.因此在Silverlight中使用SESSION的说法并不准确, 只因大家经常这样搜索才起这个名字. 有两种方法实现Silv ...

  9. 封装Html5 Fullscreen API

    复制前言: 使用新的全屏 API,可以将用户的注意力导向特定元素,同时隐藏背景或转移对其他应用的注意力.因为W3C全屏规范还未达到最终版本,所以大多数浏览器供应商都使用唯一标识符为 API 添加前缀. ...

  10. [译]MongoDb生产环境注意事项

    译注: 本文是翻译MongoDB Manuel中的MongoDB Production Notes一节内容.这节内容重点关注生产环境中影响性能和可靠性的各种注意事项,值得正在部署MongoDB的工作者 ...