forked from Estom/notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhuawei.cpp
More file actions
51 lines (46 loc) · 1.15 KB
/
huawei.cpp
File metadata and controls
51 lines (46 loc) · 1.15 KB
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
#include<iostream>
#include<vector>
using namespace std;
vector<vector<int>> gameOfLife(vector<vector<int>> board) {
vector<vector<int>> res(board.size(),vector<int>(board[0].size(),0));
for(int i=0;i<board.size();i++){
for(int j=0;j<board[0].size();j++){
int count =0;
for(int k=0;k<9;k++){
int x = i-1+k/3;
int y = j-1+k%3;
if(x==i&&y==j){
continue;
}
if(x>=0 && x<board.size() && y>=0 && y<board[0].size()&&board[x][y]==1){
count++;
}
}
if(count<2 ||count>3){
res[i][j]=0;
}
else if(count==3){
res[i][j]=1;
}
else if(count==2 && board[i][j]==1){
res[i][j]=1;
}
}
}
return res;
}
int main(){
vector<vector<int>> vec = {
{0,1,0},
{0,0,1},
{1,1,1},
{0,0,0}
};
vector<vector<int>> res= gameOfLife(vec);
for(auto a:res){
for(auto b:a){
cout<<b<<" ";
}
cout<<endl;
}
}