A. Lights out

Source: Internet
Author: User
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 × every 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 aggressive.J-Th number inI-Th
Row is the number of timesJ-Th Light ofI-Th
Row of the grid is pressed.

Output

Print three lines, each containing three characters.J-Th character ofI-Th
Line is "1" if and only if the corresponding light is switched on, otherwise it's "0 ".

Sample test (s) Input
1 0 00 0 00 0 1
Output
001010100
Input
1 0 18 8 82 0 3
Output
010011100

Solution Description: This is a simple two-dimensional array question. It is necessary to constantly determine whether the array is out of bounds. Here I wrote a child program to change the light bulb status, making the code much simpler.

#include<cstdio>#include<iostream>using namespace std;int b[3][3];void change(int i,int j){if(b[i][j]==0){b[i][j]=1;}else{b[i][j]=0;}}int main(){int i,j,a[3][3];for(i=0;i<3;i++){for(j=0;j<3;j++){b[i][j]=1;scanf("%d",&a[i][j]);}}for(i=0;i<3;i++){for(j=0;j<3;j++){a[i][j]=a[i][j]%2;if(a[i][j]!=0){change(i,j);if(i-1>=0){change(i-1,j);}if(i+1<3){change(i+1,j);}if(j-1>=0){change(i,j-1);}if(j+1<3){change(i,j+1);}}}}for(i=0;i<3;i++){for(j=0;j<3;j++){printf("%d",b[i][j]);}printf("\n");}return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.