-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix_counter_clock.cpp
More file actions
38 lines (36 loc) · 879 Bytes
/
Copy pathmatrix_counter_clock.cpp
File metadata and controls
38 lines (36 loc) · 879 Bytes
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
#include <iostream>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int arr[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> arr[i][j];
}
}
int rs = 0, re = n - 1, cs = 0, ce = m - 1;
while (rs <= re && cs <= ce) {
for (int row = rs; row <= re; row++) {
cout << arr[row][cs] << " ";
}
cs++;
for (int col = cs; col <= ce; col++) {
cout << arr[re][col] << " ";
}
re--;
if (cs <= ce) {
for (int row = re; row >= rs; row--) {
cout << arr[row][ce] << " ";
}
ce--;
}
if (rs <= re) {
for (int col = ce; col >= cs; col--) {
cout << arr[rs][col] << " ";
}
rs++;
}
}
return 0;
}