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. Valid Parentheses [LeetCode 20]

    1- 问题描述 Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if ...

  2. php7对redis的扩展及redis主从搭建

    这两天在学习一下php7下面的安装及redis相关配置认识.并将笔记记下来.以备后用.主要涉及到redis的扩展php-redis 及redis主从的配置. 一:redis安装     1:下载并安装 ...

  3. eclipse 中maven项目右键没有maven菜单问题

    修改项目.project文件,确保有maven2Builder和maven2Nature2个标签: <?xml version="1.0" encoding="UT ...

  4. sublime几个有用的快捷键

    几个有用的快捷键:Ctrl+D:选择多个相同字符串进行修改.选中字符串,按住Ctrl+D,继续选中下一个.Ctrl+Shift+L:将选中的内容切割成多行,然后每一行可以同时编辑Ctrl+J:将已选择 ...

  5. SVG矢量图--爱心

    aixin.xml: <!-- height:width=viewportHeight:viewportWidth --> <vector xmlns:android="h ...

  6. DevExpress 中 WaitForm 使用

    第一步: 在程序中拖入: splashScreenManager1 控件 在需要处理的地方 使用以下语句来打开 WaitForm窗体(当然需要在 splashScreenManager1控件中绑定一个 ...

  7. Css 书写规范【转】

    1. 不同浏览器元素的默认属性有所不同,使用Reset可重置浏览器元素的一些默认属性,以达到浏览器的兼容. /** 清除内外边距 **/ body, h1, h2, h3, h4, h5, h6, h ...

  8. Hive启动时的棘手问题的处理

    Hive是存在于Hadoop集群之上的数据仓库,作为大数据处理时的主要工具,对于大数据开发人员的重要性不言而喻.当然要使用Hive仓库的前提就是对于hive的安装,hive的安装是很简单的过程,主要关 ...

  9. 包装类(Wrapper Class)

    1)包装类.针对于原生数据类型的包装.所有的包装类(8个)对位于java.lang包下.java中的8个包装类分别是:Byte,Short,Integer,Long,Float.Double,Char ...

  10. 对Iframe和图表设置高度的优质代码

    //对Iframe和图表设置高度 function f() { parent.window.setWinHeight(parent.window.document.getElementById(&qu ...