Codeforces Round #168 (Div. 2) A. Lights Out(模拟)

A. Lights Out
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Lenny is playing a game on a 3 × 3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on.

Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light.

Input

The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The j-th number in the i-th row is the number of times the j-th light of the i-th row of the grid is pressed.

Output

Print three lines, each containing three characters. The j-th character of the i-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0".

Sample test(s)
Input
1 0 0
0 0 0
0 0 1
Output
001
010
100
Input
1 0 1
8 8 8
2 0 3
Output
010
011
100

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 
 5 using namespace std;
 6 
 7 int map[4][4], cnt[4][4];
 8 const int pos[4][2] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
 9 
10 bool Judge(int i, int j)
11 {
12     return (i < 3 && i >= 0 && j < 3 && j >= 0);
13 }
14 
15 void Press(int i, int j)
16 {
17     cnt[i][j] += map[i][j];
18     for(int k = 0; k < 4; k++)
19     {
20         int ii = i + pos[k][0];
21         int jj = j + pos[k][1];
22         if(Judge(ii, jj))
23             cnt[ii][jj] += map[i][j];
24     }
25 }
26 
27 int main()
28 {
29     while(scanf("%d", &map[0][0]) != EOF)
30     {
31         memset(cnt, 0, sizeof(cnt));
32         Press(0, 0);
33         for(int i = 0; i < 3; i++)
34         {
35             for(int j = 0; j < 3; j++)
36             {
37                 if(!i && !j) continue;
38                 scanf("%d", &map[i][j]);
39                 Press(i, j);
40             }
41         }
42         for(int i = 0; i < 3; i++)
43         {
44             for(int j = 0; j < 3; j++)
45                 printf("%d", 1 - (cnt[i][j] & 1));
46             puts("");
47         }
48     }
49     return 0;
50 }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值