用string存储矩阵逆时针旋转90度c++
时间: 2024-02-12 10:00:46 浏览: 99
矩阵求逆c++.
以下是使用string存储矩阵逆时针旋转90度的C++代码示例:
```cpp
#include <iostream>
#include <vector>
#include <string>
using namespace std;
void rotateMatrix(vector<string>& matrix) {
int n = matrix.size();
vector<string> rotatedMatrix(n, string(n, ' '));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
rotatedMatrix[j][n - i - 1] = matrix[i][j];
}
}
matrix = rotatedMatrix;
}
int main() {
vector<string> matrix = {
"123",
"456",
"789"
};
rotateMatrix(matrix);
for (const string& row : matrix) {
cout << row << endl;
}
return 0;
}
```
输出结果为:
```
369
258
147
```
阅读全文