-
Notifications
You must be signed in to change notification settings - Fork 288
/
Copy pathAC_reverse_matrix_n2.cpp
44 lines (39 loc) · 1.02 KB
/
AC_reverse_matrix_n2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* Author: illuz <iilluzen[at]gmail.com>
* File: AC_reverse_matrix_n2.cpp
* Create Date: 2014-12-24 11:29:30
* Descripton: reverse matrix and reverse every line
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 0;
class Solution {
public:
void rotate(vector<vector<int> > &matrix) {
int n = matrix.size();
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++)
swap(matrix[i][j], matrix[j][i]);
for (int i = 0; i < n; i++)
reverse(matrix[i].begin(), matrix[i].end());
}
};
int main() {
int n;
Solution s;
while (cin >> n) {
vector< vector<int> > m;
for (int i = 0; i < n; i++) {
m.push_back(vector<int>(n));
for (int j = 0; j < n; j++)
scanf("%d", &m[i][j]);
}
s.rotate(m);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
cout << m[i][j] << ' ';
cout << endl;
}
}
return 0;
}