Conforming to Code ================== Your sysadmin job is at an architecture firm. One day one of the architects comes up to you and asks if you can write a bit of software for him. He wants to provide a floorplan with a set of exits and a set of locations. The locations are places where he must place exit-instructions in order to be up to fire-codes. He wants the software to determine which of the exits are closest to each location and how far it is to the exit. Input ----- The first line of the input file will specify how many floorplans are in the file. Each floorplan starts out with two numbers on a line specifying the length and width of the floorplan, in that order. It will be formatted as: [Length] [Width] The length and width are bounded: 4 <= Length <= 70 4 <= Width <= 20 After the dimensions line there will be a representation of the floorplan with Width lines of Length characters each. Each character corresponds to 1 square yard of the floorplan. Walls are represented by hash/pound symbols (#). The outside, rectangular perimeter will always be one continuous wall. All other characters (numbers for exits, letters for sign locations, and periods to denote empty space) are considered open: hallways or rooms. There may be between 1 and 9 exits labeled with the characters '1' through '9' (but without the quotes). The exit labels will not skip any values, that is, if there are four exits, then they will be labeled '1', '2', '3' and '4', although they could appear in any order in the input stream. Exit symbols may appear anywhere (except for the outside perimeter which is always a wall). There may be between 1 and 26 locations for signs labeled with the characters 'A' through 'Z' (again without the quotes and always upper-case). They, too, will not skip any values, that is, if there are 3 signs, they will be labeled 'A', 'B', and 'C'. Sign symbols, too, may appear anywhere, in any order, not on the outside perimeter. Legal paths from signs to exits may only include movements UP, DOWN, LEFT or RIGHT (relative to the representation onscreen)- no diagonal movement is allowed. It is guaranteed that there is at least one path from every sign to at least one exit. Open areas are marked with the period character (.). Every position inside the outside perimeter will contain a character, either a '#' for walls, a digit for exits, a letter for sign locations or a period for open space. Remember that exit (1-9) and sign (A-Z) symbols, too, are open areas and may be "passed through". Walls (#) are impassible. Output ------ The output will consist of one line per sign per floorplan that contains the name of the closest exit and how far away it is from the sign. It should be formatted as follows: Floorplan [F]: People at sign [S] should proceed to exit [E] ([D] yards). [F] is the floorplan number - an integer that starts at 1 and increments by 1 for each floorplan processed [S] is the sign-letter - a single uppercase letter [E] is the exit-number - a single-digit decimal number [D] is the distance in characters (yards) from the sign to the exit. The distance is the number of characters in the path INCLUDING the exit but EXCLUDING the sign. The output for each floorplan must be sorted by sign-letter. If there is a tie (two or more exits are the same distance away from the same sign), output the lowest-number exit. Sample Input ------------ 3 6 5 ###### #...1# #.A.## #.#2## ###### 6 6 ###### #.#B.# #..#.# #.A#.# #1..2# ###### 8 8 ######## #1....2# #.####.# #.#...B# #.##A### #.#.C..# #3..##4# ######## Sample Output ------------- Floorplan 1: People at sign A should proceed to exit 2 (2 yards). Floorplan 2: People at sign A should proceed to exit 1 (2 yards). Floorplan 2: People at sign B should proceed to exit 2 (4 yards). Floorplan 3: People at sign A should proceed to exit 4 (4 yards). Floorplan 3: People at sign B should proceed to exit 2 (2 yards). Floorplan 3: People at sign C should proceed to exit 4 (3 yards).