矩阵的翻转
2014-11-24 11:13
218 查看
// 翻转矩阵.cpp : 定义控制台应用程序的入口点。
//
#include"stdafx.h"
#include<iostream>
#include<time.h>
#include<algorithm>
usingnamespace std;
#define M8
int randgener()
{
return(rand()%100);
}
void print(int** a)
{
for(int i=0; i< M; i++)
{for(int
j=0; j<
M; j++)[/code]{[/code]cout<<
a[i][j]<<"\t";[/code]}[/code]cout<<
endl;[/code]}[/code]
}
void swap(int& a ,int& b)
{int
temp= a;[/code]a=
b;[/code]b=
temp;[/code]
}
voidReserve(int** a,int m)
{if(NULL==
a)[/code]return;[/code]int
low=0;[/code]int
high= m;[/code]while(low<
high)[/code]{[/code]swap(a[low][low],
a[low][high]);[/code]swap(a[low][low],
a[high][high]);[/code]swap(a[low][low],
a[high][low]);[/code]for(int
i= low+1;
i<= high-1;
i++)[/code]{[/code]swap(a[low][i],
a[i][high]);[/code]swap(a[low][i],
a[high][m-i]);[/code]swap(a[low][i],
a[m-i][low]);[/code]}[/code]low++;[/code]high--;[/code]cout<<
endl;[/code]
}}[/code]
int main()
{int**
a=newint*[M];[/code]int*
b=newint[M*M+1];[/code]for(int
i=0; i<
M; i++)[/code]a[i]=
b+ i*M;[/code]generate(b,
b+M*M,
randgener);//初始化矩阵---好方法[/code]print(a);[/code]Reserve(a,
M-1);[/code]cout<<
endl;[/code]print(a);[/code]return0;[/code]
}
一圈一圈的转
相关文章推荐
- 计蒜客 挑战难题 第5题:矩阵翻转
- 矩阵的转置变换、翻转行/列和旋转
- 计蒜客-矩阵翻转
- 计蒜客挑战难题:矩阵翻转
- Nyoj 298 点的变换[利用矩阵求解坐标点的转换,平移,绕原点旋转,沿x,y轴翻转]
- C语言实现矩阵翻转(上下翻转、左右翻转)
- OpenCV2学习笔记05:矩阵翻转
- 简单的矩阵的上下,左右翻转
- 【计蒜客】矩阵翻转C++
- 矩阵上下左右翻转
- 矩阵翻转的一个例子(C++)
- 我的第一篇CSDN博客文章,Python代码实现矩阵翻转
- 计蒜客 难题题库 005 矩阵翻转
- 计蒜客题库(Python):5、矩阵翻转
- 将一个矩阵翻转90度
- 矩阵翻转
- 计蒜客 判断质数,简单裴波那契数列,矩阵翻转
- 计蒜客题目 矩阵翻转
- java__晓萌最近在做一个翻转图片的应用,你可能也知道,图片其实是由一个个的点组成的。于是,晓萌想先做一个可以翻转矩阵的程序,来解决他问题的核心部分。
- HDU 4772(翻转矩阵)