1.6 图像旋转
来源:互联网 发布:数控系统模拟软件 编辑:程序博客网 时间:2024/06/09 13:41
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?
package test;
public class JumpTwo {
public static void main(String[] args) {
int[][] matr = {{1,2,3},{4,5,6},{7,8,9}};
int n=3, m=3;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
System.out.print("\t"+ matr[i][j]);
}
System.out.println();
}
System.out.println("after rotation");
rotate(matr,n);
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
System.out.print("\t"+ matr[i][j]);
}
System.out.println();
}
}
public static void rotate(int[][] s, int n) {
for(int i=0;i<n;i++){
for(int j=i;j<n-i-1;j++){ 错了好久才搞出来,还是比较困惑
int tmp=s[i][j];
s[i][j] = s[n-j-1][i];
s[n-j-1][i]= s[n-i-1][n-j-1];
s[n-i-1][n-j-1] = s[j][n-1-i];
s[j][n-1-i]=tmp;
}
}
}
}
0 0
- 1.6 图像旋转
- CI 1.6 矩阵旋转--图像旋转
- 图像旋转
- 旋转图像
- 图像旋转
- 图像旋转
- 图像旋转
- 图像旋转
- 图像旋转
- 旋转图像
- --图像旋转--
- 旋转图像
- 旋转图像
- 图像旋转
- 图像旋转
- 图像旋转
- 旋转图像
- 图像旋转
- 呃呃呃呃呃呃呃呃呃
- 痛定思痛开始刷cc150 压缩数据,使用stringBuffer
- C++ STL map的使用
- 3.1-3.3SQL 基本操作
- [2015年1月][12~18][cocos2d塔防游戏学习]
- 1.6 图像旋转
- UML基本架构建模--关联概述
- UML基本架构建模--获取关联
- UML基本架构建模--关联的术语和概念(一)
- UML基本架构建模--关联的术语和概念(二)
- UML基本架构建模--关联的术语和概念(三)
- 32位汇编语言学习笔记(41)--fgets等函数的使用
- 【博弈】【bzoj 1457】: 棋盘游戏
- Codility Lesson 4 NumberOfDiscIntersections 解答