VIM--矩阵转置运算
来源:互联网 发布:服务器网络配置自考 编辑:程序博客网 时间:2024/06/12 01:22
#include<iostream>#include<vector>using namespace std;void PrintMatrix(vector<vector<int> >& Matrix){ int n = Matrix.size(); for(int i = 0; i < n; ++i) { cout << "[" ; for(int j = 0; j < n; ++j) { cout << Matrix[i][j] ; } cout << "]"; cout << '\n'; }}void TofArray(vector<vector<int> >& matrix){ const int n = matrix.size(); // 主对角线反转 for(int i = 0; i < n; ++i) { for(int j = 0; j < n-i; ++j) swap(matrix[i][j], matrix[n-1-j][n-1-i]); } cout << "主对角线反转: " << '\n'; PrintMatrix(matrix); cout << '\n'; // 水平中线反转 for(int i = 0; i < n/2; ++i) { for(int j = 0; j < n; ++j) { swap(matrix[i][j], matrix[n-1-i][j]); } } cout << "水平中线反转: " << '\n'; PrintMatrix(matrix); cout << '\n'; // 垂直中线反转 for(int i = 0; i < n; ++i) { for(int j = 0; j < n/2; ++j) { swap(matrix[i][j], matrix[i][n-1-j]); } } cout << "垂直中线反转: " << '\n'; PrintMatrix(matrix); cout << '\n';}int main(int argc, char* argv[]){ vector<int> row1; row1.push_back(1), row1.push_back(2), row1.push_back(3); vector<int> row2; row2.push_back(4), row2.push_back(5), row2.push_back(6); vector<int> row3; row3.push_back(7), row3.push_back(8), row3.push_back(9); vector<vector<int> > Matrix(3); Matrix[0] = row1; Matrix[1] = row2; Matrix[2] = row3; cout << "Row matrix is: " << '\n'; PrintMatrix(Matrix); cout << '\n'; TofArray(Matrix); cout << "After T of Matrix is: " << '\n'; PrintMatrix(Matrix); cout << '\n'; return 0;}
0 0
- VIM--矩阵转置运算
- 转 numpy 矩阵运算[转]
- 编写一个函数实现矩阵的转置运算
- 稀疏矩阵的加法、减法、转置运算
- 利用按位异或运算符实现矩阵转置
- 矩阵运算
- 矩阵运算
- 矩阵运算
- 矩阵运算
- 矩阵运算
- 矩阵运算
- 矩阵运算
- 矩阵运算
- 矩阵运算
- 矩阵运算
- 矩阵运算
- 矩阵运算
- 矩阵运算
- Hibernate4.3.7使用session
- poj2388 简单排序——归并排序
- mac 安装SourceInsight
- 《数据结构》第五章 树和二叉树 知识总结导图
- (个人笔记)ID3DXAllocateHierarchy interface
- VIM--矩阵转置运算
- 2014.12.09深度封装工具类
- kail-linux 和win8.1 uefi 实录
- iOS App开发那些事:如何选择合适的人、规范和框架?
- 第15周 指针运算
- 暂留
- Java---10---多线程概述
- 全局变量和局部变量有什么区别?是怎么实现的?操作系统和编译器是怎么知道的?
- 【hdu 1300】pearl(需要深刻理解dp,同龟兔赛跑)