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. 开发iOS应用程序需要的工具和编程技术

    似乎每个iOS应用开发学习者都是从这篇文章开始写博客的,我也不例外,也从这里写吧,内容雷同,但绝对是原创.因为一直相信,通过自己的理解写出来,是掌握技术一个很好的途径. Xcode苹果最为优秀的集成开 ...

  2. 常用的MyEclipse快捷键

    在调试程序的时候,我们经常需要注释一些代码,在用Myeclipse编程时,就可以用 Ctrl+/ 为选中的一段代码加上以 // 打头的注释:当需要恢复代码功能的时候,又可以用Ctrl+/ 去掉注释.这 ...

  3. Unable to write inside TEMP environment path

    安装PostgreSQL 9:Unable to write inside TEMP environment path 注册表:regedit HKEY_CLASSES_ROOT\.vbs,设置默认为 ...

  4. Ubuntu CTRL+ALT+F1~F6 进入命令模式后不支持中文显示的解决办法

    前言 我在实验进入linux系统启动xwindow server而不启动KDE GNOME等桌面系统时遇到的问题.只启动x server而不启动桌面系统,在xserver之上运行一个全屏的图形界面程序 ...

  5. 当数据0跟if判断冲突的时候

    我是很无奈的,以后都要2,3,4,5这样去标志状态: 分配状态:<select name="is_send" > <option selected="s ...

  6. mysql事件调度器定时删除binlog

    MySQL5.1.6起Mysql增加了事件调度器(Event Scheduler),可以用做定时执行某些特定任务,来取代原先只能由Linux操作系统的计划任务来执行的工作MySQL的事件调度器可以精确 ...

  7. 做个伪IE浏览器?!【来自官网】

    原文:docwiki.embarcadero.com/RADStudio/Seattle/en/Building_a_VCL_Forms_Web_Browser_Application 选择File ...

  8. android 输出.txt 文本换行问题

    // 获取当前日期和时间 Calendar cal = Calendar.getInstance(); String fileName = cal.get(Calendar.YEAR) + " ...

  9. activiti

    http://activiti.org/designer/archived/  eclipse plugin

  10. Oracle Database Links解析

    什么是Database Links呢? 首先我们阐述下它的作用:使用户可以通过一个数据库访问到另外一个远程数据库. 那么Database Link是存储着远程数据库的连接信息. 如下图所示: 用户Sc ...