标签:
#include "stdafx.h" #include <iostream> #include <vector> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { vector<vector<int>>a(4, vector < int>(3)); int v = 1; //初始化一个矩阵。 for (int i = 0; i < a.size(); i++){ for (int j = 0; j < a[0].size(); j++){ a[i][j] = v++; } } vector<vector<int>>b =a; //使用b保存矩阵a for (int i = 0; i < b.size(); i++){ for (int j = 0; j < b[0].size(); j++){ cout << b[i][j] << " "; } cout << endl; } //初始化矩阵的空间 a.clear(); a.resize(b[0].size()); for (int i = 0; i < a.size(); i++){ a[i].resize(b.size()); } //制作逆时针转向的新矩阵 for (int i = 0; i < b[0].size(); i++){ for (int j = 0; j < b.size(); j++){ //a[i][j]=b[j][i]; a[b[0].size() - i - 1][j] = b[j][i]; } } //打印逆转矩阵的值 for (int i = 0; i < a.size(); i++){ for (int j = 0; j < a[0].size(); j++){ cout << a[i][j] << " "; } cout << endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/yuguangyuan/p/5913686.html