-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11a.cpp
More file actions
85 lines (76 loc) · 1.55 KB
/
11a.cpp
File metadata and controls
85 lines (76 loc) · 1.55 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <algorithm>
#include <set>
using namespace std;
vector<string>nuevo;
vector<string>viejo;
vector<pair<int,int>> coord = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
int main(){
string dato;
while(getline(cin,dato)){
viejo.push_back(dato);
}
bool bandera=true;
while(bandera){
for(int x=0; x<viejo.size();x++){
string datonuevo="";
for(int y=0;y<viejo[x].size();y++){
/*adyacencias*/
int ocupa=0;
for(auto c: coord){
if(x+c.first>=0 and y+c.second<viejo[x].size() and y+c.second>=0 and x+c.first<viejo.size()){
if(viejo[x+c.first][y+c.second]=='#'){
ocupa++;
}
}
}
if(viejo[x][y]=='L' and ocupa==0){
datonuevo.push_back('#');
}else if(viejo[x][y]=='#' and ocupa>=4){
datonuevo.push_back('L');
}else{
datonuevo.push_back(viejo[x][y]);
}
//cout<<viejo[x][y]<<endl;
}
nuevo.push_back(datonuevo);
}
int dif=0;
for(int k=0;k<nuevo.size();k++){
cout<<viejo[k]<<" "<<nuevo[k]<<endl;
if(nuevo[k]!=viejo[k]){
dif++;
}
}
if(dif==0){
bandera=false;
}else{
viejo.clear();
viejo=nuevo;
nuevo.clear();
}
cout<<endl;
//bandera=false;
}
for(auto x: nuevo){
cout<<x<<endl;
}
cout<<endl;
for(auto x: viejo){
cout<<x<<endl;
}
int res=0;
for(int a=0; a<nuevo.size();a++){
for(int b=0; b<nuevo[a].size(); b++){
//cout<<nuevo[a][b];
if(nuevo[a][b]=='#'){
res++;
}
}
//cout<<endl;
}
cout<<res<<endl;
}