-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA_Game_of_Life.cpp
49 lines (43 loc) · 1.02 KB
/
A_Game_of_Life.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
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define ll long long
int main()
{
ll t;
cin >> t;
while (t--)
{
long long int n, m;
cin >> n >> m;
string s;
cin >> s;
vector<int> v;
for (int j = 0; j < min(n, m); j++)
{
for (int i = 0; i < n; i++)
{
if (i == 0)
{
if (s[i] == '0' && s[i + 1] == '1')
{
v.push_back(i);
}
}
else if (i == n - 1)
{
if (s[i] == '0' && s[i - 1] == '1')
v.push_back(i);
}
else
{
if (s[i] == '0' && (s[i + 1] - '0' + s[i - 1] - '0') == 1)
v.push_back(i);
}
}
for (auto x : v)
s[x] = '1';
}
cout << s << endl;
}
}