-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP48.cpp
47 lines (43 loc) · 929 Bytes
/
P48.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
44
45
46
47
#include<algorithm>
#include<vector>
#include<iostream>
#include<string>
#include<stack>
using namespace std;
class Solution {
public:
void rotate(vector<vector<int>>& matrix) {
int n;
int i,j;
n=matrix.size();
for (i=0;i<n;i++)
for (j=i+1;j<n;j++)
swap(matrix[i][j],matrix[j][i]);
for (i=0;i<n;i++)
for (j=0;j<n/2;j++)
swap(matrix[i][j],matrix[i][n-1-j]);
return;
}
};
static const auto io_sync_off = []()
{
// turn off sync
std::ios::sync_with_stdio(false);
// untie in/out streams
std::cin.tie(nullptr);
return nullptr;
}();
int main() {
vector<vector<int>> m={
{5,1,9,11},
{2,4,8,10},
{13,3,6,7},
{15,14,12,16}};
Solution().rotate(m);
for (auto i:m) {
for (auto j:i)
cout<<j<<" ";
cout<<endl;
}
return 0;
}