The Dreadful Seven
All submissions for this problem are available.
The Dreadful Seven
Super Mario is studying how to use a mysterious Power Square. The Power Square is n×n with integer values between 0 and n^2 − 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 ﬁnd 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 is a description of of the Power Square, followed by a number of commands. The ﬁrst line is the size of the Power Square n. You may assume n ≤ 100. The second line contains the n^2 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 ﬁlled.
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.
• 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 neighbouring 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.
EXAMPLE IS GIVEN IN BOTH INPUT OUTPUT
FORMAT. AFTER 'SHOW' THE GRID MUST BE
DISPLAYED AND AFTER EACH 'NEIGHBORS'
COMMAND RESPECTIVE OUTPUT MUST BE
3 8 7 6 5 4 3 2 1 0 SHOW 8 7 6 5 4 3 2 1 0 NEIGHBORS 7 8 6 4 NEIGHBORS 1 4 2 0 NEIGHBORS 4 7 5 3 1
Example 2: 4 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 SHOW 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 NEIGHBORS 7 3 6 11 NEIGHBORS 1 0 2 5 NEIGHBORS 8 4 9 12 NEIGHBORS 14 10 13 15
|Time Limit:||0.8 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, PYP3, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.