//原文:
//
// Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees. Can you do this in place?
//
// 先转置在上下交换 #include <iostream>
using namespace std;
void swap(int &a, int &b)
{
int t=a;
a=b;
b=t;
}
void replace(int **matrix, int size)
{
for (int i = 0;i<size; i++)
{
for (int j=i;j<size; j++)
{
swap(matrix[i][j],matrix[j][i]);
}
} for (int i = 0; i<size/2; i++)
{
for (int j=0;j<size; j++)
{
swap(matrix[i][j],matrix[size-1-i][j]);
}
}
}
void display(int **matrix, int size)
{
for (int k = 0; k<size; k++)
for (int t = 0; t<size; t++)
{
cout<<matrix[k][t];
if (t==size-1)
{
cout<<endl;
}
}
}
int main()
{
int size = 4;
int **p = new int *[size];
for (int i=0; i<size; i++)
{
p[i] = new int[size];
} for (int k = 0; k<size; k++)
for (int t = 0; t<size; t++)
{
p[k][t] = 2*k+t;
}
display(p,size);
replace(p,size);
cout<<endl;
display(p,size); int a=3,b=4;
swap(a,b); for (int k=0;k<size;k++)
{
delete [] p[k];
}
delete p;
return 0;
}

Cracking The Coding Interview 1.6的更多相关文章

  1. Cracking the coding interview

    写在开头 最近忙于论文的开题等工作,还有阿里的实习笔试,被虐的还行,说还行是因为自己的水平或者说是自己准备的还没有达到他们所需要人才的水平,所以就想找一本面试的书<Cracking the co ...

  2. Cracking the coding interview 第一章问题及解答

    Cracking the coding interview 第一章问题及解答 不管是不是要挪地方,面试题具有很好的联系代码总用,参加新工作的半年里,做的大多是探索性的工作,反而代码写得少了,不高兴,最 ...

  3. Cracking the Coding Interview(Trees and Graphs)

    Cracking the Coding Interview(Trees and Graphs) 树和图的训练平时相对很少,还是要加强训练一些树和图的基础算法.自己对树节点的设计应该不是很合理,多多少少 ...

  4. Cracking the Coding Interview(Stacks and Queues)

    Cracking the Coding Interview(Stacks and Queues) 1.Describe how you could use a single array to impl ...

  5. 《Cracking the Coding Interview》读书笔记

    <Cracking the Coding Interview>是适合硅谷技术面试的一本面试指南,因为题目分类清晰,风格比较靠谱,所以广受推崇. 以下是我的读书笔记,基本都是每章的课后习题解 ...

  6. Cracking the coding interview目录及资料收集

    前言 <Cracking the coding interview>是一本被许多人极力推荐的程序员面试书籍, 详情可见:http://www.careercup.com/book. 第六版 ...

  7. 《Cracking the Coding Interview》——第13章:C和C++——题目6

    2014-04-25 20:07 题目:为什么基类的析构函数必须声明为虚函数? 解法:不是必须,而是应该,这是种规范.对于基类中执行的一些动态资源分配,如果基类的析构函数不是虚函数,那么 派生类的析构 ...

  8. 《Cracking the Coding Interview》——第5章:位操作——题目7

    2014-03-19 06:27 题目:有一个数组里包含了0~n中除了某个整数m之外的所有整数,你要设法找出这个m.限制条件为每次你只能用O(1)的时间访问第i个元素的第j位二进制位. 解法:0~n的 ...

  9. 二刷Cracking the Coding Interview(CC150第五版)

    第18章---高度难题 1,-------另类加法.实现加法. 另类加法 参与人数:327时间限制:3秒空间限制:32768K 算法知识视频讲解 题目描述 请编写一个函数,将两个数字相加.不得使用+或 ...

  10. 《Cracking the Coding Interview 》之 二叉树的创建 与 遍历(非递归+递归version)

    #include <iostream> #include <cstdio> #include <vector> #include <stack> #de ...

随机推荐

  1. Fat jar用途

    1.Fat jar用途 我们都知道默认的eclipse下打包jar时,是无法连同外部引用包一起打包的.所以一般我们可以自己编写MINIFEST.MF文件来手动将需要的jar包加入进来,但是这样对于引用 ...

  2. 微信小程序页面内转发 按钮 转发

    通过给 button 组件设置属性 open-type="share",可以在用户点击按钮后触发 Page.onShareAppMessage() 事件,如果当前页面没有定义此事件 ...

  3. appium自动化环境搭建(python语言开发)

    简述 1.安装jdk,配置环境变量 2.安装AndroidSDK,配置环境变量 3.安装Python 4.安装Python集成开发环境PyCharm 5.安装node 6.安装appium服务端 7. ...

  4. react中的核心概念

    DOM:浏览器中提供的概念: 虚拟DOM:框架中的概念:需要开发框架的程序员手动用JS对象来模拟DOM元素和嵌套关系: 本质:用JS对象,模拟DOM树: 目的:实现页面的按需更新: 要求:点击列头,实 ...

  5. z-index注意事项

    1. z-index只对定位元素有效(如position:absolute!) 2. 被覆盖的元素将无法触发其鼠标相关事件.(个人经验,可能有例外.) 3. 无法通过z-index使父级覆盖子级,如果 ...

  6. find xss

    from :http://blog.sina.com.cn/s/blog_68d342d90100nh7b.html 什么是XSS跨站攻击: http://baike.baidu.com/view/5 ...

  7. SQL SERVER 子查询使用Order By;按In排序

    [子查询]使用order by percent * from table order by id) a 这时发现结果没有按id排序,需要将100 percent 改成 99.999 percent 或 ...

  8. arguments.callee用法

    arguments.callee 在哪一个函数中运行,它就代表哪一个函数. 一般用在匿名函数中. 在匿名函数中有时会需要自己调用自己,但是由于是匿名函数,没有名子,无名可调. 这时就可以用argume ...

  9. linux的越墙方法

    .首先要安装openSSH, Ubuntu缺省没有安装SSH Server,使用以下命令安装: sudo apt-get install openssh-server 但是系统有时候会出现E类错误,无 ...

  10. vs 2017 Integrated Security 为sspi 含义

    关于sql连接语句中的Integrated Security=SSPI解决方法:即:Security Support Provider Interface设置Integrated Security为 ...