矩阵行成列,列成行

时间:2021-12-28 10:32:39
 1 #include<iostream>
 2 #include<vector>
 3 using namespace std;
 4 int main()
 5 {
 6     vector<vector<int>> vet;
 7     for (int i = 0; i < 3; i++)
 8     {
 9         vector<int> vet1;
10         for (int j = 0; j < 3; j++)
11         {
12             int x;
13             cin >> x;
14             vet1.push_back(x);
15         }
16         vet.push_back(vet1);
17     }
18     for (int i = 0; i < 3; i++)
19     {
20         for (int j = 0; j < 3; j++)
21         {
22             cout << vet[i][j] << " ";
23         }
24         cout << endl;
25     }
26     vector<vector<int>> cp;
27     cp = vet;
28     for (int i = 0; i < 3; i++)
29     {
30         for (int j = 0; j < 3; j++)
31         {
32             vet[i][j] = cp[j][i];
33         }
34     }
35     for (int i = 0; i < 3; i++)
36     {
37         for (int j = 0; j < 3; j++)
38         {
39             cout << vet[i][j] << " ";
40         }
41         cout << endl;
42     }
43     system("pause");
44     return 0;
45 }