-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlightsOut.cpp
More file actions
37 lines (36 loc) · 928 Bytes
/
Copy pathlightsOut.cpp
File metadata and controls
37 lines (36 loc) · 928 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
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n = 3;
int a[n][n];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
a[i][j] = 1;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
int x;
cin >> x;
if (x & 1 != 0)
{
a[i][j] = (a[i][j] == 1) ? 0 : 1;
if (i > 0)
a[i - 1][j] = (a[i - 1][j] == 1) ? 0 : 1;
if (i < n - 1)
a[i + 1][j] = (a[i + 1][j] == 1) ? 0 : 1;
if (j > 0)
a[i][j - 1] = (a[i][j - 1] == 1) ? 0 : 1;
if (j < n - 1)
a[i][j + 1] = (a[i][j + 1] == 1) ? 0 : 1;
}
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
cout << a[i][j];
cout << "\n";
}
}