//原文:
//
// 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;
}

最新文章

  1. 用libcurl 登录网站
  2. java类加载器加载文件
  3. Swift 02.Array
  4. 【Origin】 偶题 之 抒意
  5. sqlserver 索引
  6. js的Touch事件
  7. Oracle中分页查询语句
  8. Json数据转换
  9. 如何制作windows服务安装包
  10. 神经网络与深度学习笔记 Chapter 6之卷积神经网络
  11. 使用 Kafka 和 ELK 搭建测试日志系统(1)
  12. 也谈Reactor模式
  13. 全文搜索引擎——Solr
  14. OneAPM 重磅登陆 CTDC 2018展示“ AIOps 双雄”创新实力
  15. 回调函数: 一定要在函数名前加上 CALLBACK,否则有可能引起内存崩溃!
  16. 一个简单的mock server
  17. 使用nagios监控ssl证书过期时间
  18. stark组件开发之列表页面定制列
  19. &gt;/dev/null 2&gt;&amp;1 这句话的含义及使用的意义
  20. webuploader在ie7下的flash模式的使用

热门文章

  1. Yii2给数据库表添加字段后对应模型无法识别到该属性的原因和解决办法
  2. English trip M1 - AC1 My Dream Car Teacher:Corrine
  3. 微信小程序双击事件的绑定
  4. Pytorch半精度浮点型网络训练问题
  5. 初次安装git配置用户名和邮箱
  6. UI BOL 练习 get value set attr
  7. 针对unicode对象---检测字符串是否只由数字组成
  8. ubuntu分辨率
  9. Zookeeper面试题
  10. linux下grep命令详解