forked from xperzy/careerup150
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1-7.cpp
75 lines (63 loc) · 1.12 KB
/
1-7.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#include <string>
using namespace std;
class Solution{
public:
void rotate(int a[][5], int n){
bool col=true;
bool row=true;
for (int i=0;i<n;i++) {
if (a[i][0]==0) {col=false;}
if (a[0][i]==0) {row=false;}
}
for(int i=1;i<n;i++){
for (int j=1;j<n;j++) {
if (a[i][j]==0){
a[0][j] =0;
a[i][0] = 0;
}
}
}
for (int i=0;i<n;i++){
if (a[0][i]==0) {
for (int j = 0;j<n;j++) {
a[j][i]=0;
}
}
if (a[i][0]==0) {
for (int j=0;j<n;j++) {
a[i][j]=0;
}
}
}
if (!row){
for (int i=0;i<n;i++){
a[0][i]=0;
}
}
if (!col){
for (int i=0;i<n;i++){
a[i][0]=0;
}
}
}
};
int main(){
Solution sol;
int a[5][5] = {{1,0,3,4,5}, {1,2,3,0,5}, {0,2,3,4,5}, {1,2,3,4,5}, {1,2,3,4,5}};
for (int i=0;i<5;i++){
for (int j=0;j<5;j++){
cout << a[i][j] << " ";
}
cout << endl;
}
cout << endl;
sol.rotate(a,5);
for (int i=0;i<5;i++){
for (int j=0;j<5;j++){
cout << a[i][j] << " ";
}
cout << endl;
}
return 0;
}