|
||||||||||
The Dreadful SevenTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 547 Accepted Submission(s): 221 Problem Description Super Mario is studying how to use a mysterious Power Square. The Power Square is n¡Án with integer values between 0 and n2-1. A number y is a neighbor of another number x in the Power Square if y is directly above or below x, or directly to the left or right of x. Rosalina asks Super Mario to find all the numbers in the Power Square that are neighbors of the number 7, since she can tell that those numbers are quite nervous. ¡±Why are the numbers scared of seven?¡± Mario asks Rosalina. ¡±Because seven ate nine!¡± Rosalina exclaims. Input Input is a description of of the Power Square, followed by a number of commands. The first line is the size of the Power Square n. You may assume n<=100. The second line contains the n2 values in the Power Square, separated by spaces. Values start from the top left corner and move from left to right, moving down one row to the leftmost position when a row is filled. Following the Power Square description are a number of commands, with each command on a separate line. Each command begins with the name of the command, followed by any additional command parameters. There will no more than 100 commands. Output The command ¡±SHOW¡± causes the current state of the Power Square to be displayed in n ¡Á n form (each row of n values on a single line, separated by spaces), followed by a blank line. The command ¡±NEIGHBORS¡± is followed by a value x in the Power Square. The values neighboring x are output and displayed on a single line (in the order: above, left, right, and below x), separated by spaces. You may assume that x is always in the Power Square. Sample Input
Sample Output
Source | ||||||||||
|