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 00 0 00 0 1
output
001010100
input
1 0 18 8 82 0 3
output
010011100
題目大意:現(xiàn)有3*3個開關(guān),初始全為開著。切換(開變成關(guān),關(guān)變成開)每個開關(guān)的時候,與它直接相鄰的四個方向上的開關(guān)也會切換,給出每個開關(guān)的切換次數(shù),問最后各個開關(guān)的狀態(tài)。
解題思路:我們只需要判斷每個開關(guān)到最后總共被切換了多少次,直接判斷次數(shù)的奇偶即可判斷某個開關(guān)最后的狀態(tài)。直接遍歷每個開關(guān),但是如果直接在原來的開關(guān)次數(shù)上加,會影響對后來的計算,所以,我們開了兩個數(shù)組,A[][]和B[][],A是輸入的每個開關(guān)的切換次數(shù),B是最后每個開關(guān)切換的總次數(shù)。最后在掃一遍B即可,若B[i][j]是奇數(shù),則狀態(tài)為0(關(guān)),否則狀態(tài)為1(開)。
AC代碼:
#include#include #include #include #include #include #include #include
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com