Cracking The Coding Interview 1.6
来源:互联网 发布:淘宝宝贝如何排名靠前 编辑:程序博客网 时间:2024/05/22 01:54
//原文:////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;}
0 0
- Cracking The Coding Interview 1.6
- Cracking the Coding Interview
- 《Cracking the coding interview》
- Cracking The Coding Interview
- Cracking the coding interview
- Cracking the coding interview
- Cracking the coding interview--Q1
- Cracking the coding interview--Q17
- Cracking the coding interview--Q2
- Cracking the coding interview--Q3
- Cracking the coding interview--Q4
- Cracking the coding interview--Q5
- Cracking the coding interview--Q8
- Cracking the coding interview--Q9
- Cracking the coding interview 题目
- Cracking The Coding Interview 1.1
- Cracking The Coding Interview 1.2
- Cracking The Coding Interview 1.3
- 分享Android开发的一些工具
- 只要998!苹果新项目iAd或成“电视购物”
- 容器list使用之erase
- 网易上关于wifi产品的相关介绍总结
- php 使用serialize() 和 unserialize() 让对象成超级变量
- Cracking The Coding Interview 1.6
- IIS7.5出现ASP.NET网站"已成功与服务器建立连接,但是在登录过程中发生错误。"
- stl中的vector,list,deque,map,set的区别
- 身边的逻辑学——简单的真理不简单(2) 无论如何,清晰思考利多于弊
- "葫芦娃"翻拍引吐槽 制作方:目的严肃 不为博眼球
- jdbc操作数据库帮助类
- 基于struts拦截器的登录验证
- 并发内存分配TBB的解决方案
- 我的博客(总目录)