//原文:
//
// 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. (转)UCOSII在任务切换与出入中断时堆栈指针的使用

    1 uc/os ii在M3中的堆栈结构 1.1 M3入账序列  1.2 加上手工入栈序列  2 PendSV在Cortex-M3中的应用 Systick为嵌入到内核中,优先级比一般中断优先级高.若在一 ...

  2. Getting started with Processing 第十三章——延伸(1)

    导入库: 导入库的名称为:import processing.libName.* 声音 播放声音 支持的格式:wav,aiff,mp3声明: SoundFile blip;创建:blip = new ...

  3. Yii2给数据库表添加字段后对应模型无法识别到该属性的原因和解决办法

    Yii2给数据库表添加字段后对应模型无法识别到该属性的原因和解决办法 应为数据库表的结构被缓存了.删除runtime文件夹或者执行 //清理指定表结构缓存数据 Yii::$app->db-> ...

  4. 如何通过ssh远程登录内网的Mac和Linux系统?

    神器:ngrok 用法很简单,安装后 验证授权: ./ngrok authtoken 3WWujp1TEtHRo6rphEi5Y_7MBqGWm9yThCSFyqEHgip 在内网开启tcp服务 ng ...

  5. English trip V1 - B 4.How Do You Make a Salad? 请给我一间房? Teacher:Julia Key:imperatives 祈使句

    In this lesson you will learn to give instructions. 这节课你将将学会给出指示. 课上内容(Lesson) 词汇(Key Word ) bell pe ...

  6. 快速幂的求解-java方法(int范围之内)

    思想就是,将十进制数化成二进制数.其它就是很简单了. 如:2的11次幂,11的二进制位1011,所以2(11) = 2(2(0) + 2(1) + 2(3)); 具体实现步骤,看代码比较简单 impo ...

  7. MyEclipse6.5的反编译插件的安装

    常用的几种反编译工具 1. JD-GUI[推荐] JD-GUI是属于Java Decompiler项目(JD项目)下个的图形化运行方式的反编译器.JD-Eclipse属于Java Decompiler ...

  8. stark 组件 url 二级分发的实现

    模拟 admin 组件url设计思路 项目urls 文件中: from django.contrib import admin from django.urls import path from st ...

  9. 代码版本控制[version control]之Git

    如何多人协同开发同一个项目? 使用代码版本控制[version control]软件, 目前市面上比较流行的代码版本控制器有: git,svn,csv 1. 使用git管理代码版本 本项目使用git管 ...

  10. Maxim and Array CodeForces - 721D (贪心)

    大意: 给定序列, 每次操作选择一个数+x或-x, 最多k次操作, 求操作后所有元素积的最小值 贪心先选出绝对值最小的调整为负数, 再不断选出绝对值最小的增大它的绝对值 #include <io ...