TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

RelativeCoordinates

Problem statement, definition, constraints, and public examples.

Problem Statement

Your function will be fed a String[] screen containing the output of a radar device. screen will contain exactly one 'Y' and one or more 'T's. The remaining characters are all periods ('.'). 'Y' designates your position on the radar. 'T' designates an enemy position. You will return a int[] containing the relative distances from your position to each enemy in screen. The relative distance is the absolute difference in rows added to the absolute difference in columns. Here absolute difference means take the absolute value of the difference. For example, if
screen = {"....T...",
          "Y.......",
          ".......T"}
then the higher 'T' has relative distance 5 (1 row, 4 columns) and the lower 'T' has relative distance 8 (1 row, 7 columns). Enemies that occur earlier in screen should occur earlier in the return value. If two enemies are in the same element of screen, the enemy that occurs earlier in that element should occur earlier.

Definition

Class:
RelativeCoordinates
Method:
getCoords
Parameters:
String[]
Returns:
int[]
Method signature:
int[] getCoords(String[] screen)
(be sure your method is public)

Constraints

  • screen must contain between 1 and 50 elements inclusive.
  • Each element of screen must contain between 1 and 50 characters inclusive.
  • Each element of screen must contain the same number of characters.
  • Each character in screen will be (quotes for clarity) '.', 'T', or 'Y'.
  • screen will contain exactly one 'Y'.
  • screen will contain between 1 and 100 'T' characters inclusive.

Examples

  1. {"....T...",
     "Y.......",
     ".......T"}
    Returns: { 5,  8 }
    From above.
  2. {"YTTTTTTTTTT"}
    Returns: { 1,  2,  3,  4,  5,  6,  7,  8,  9,  10 }
  3. {"T"
    ,"T"
    ,"T"
    ,"T"
    ,"T"
    ,"T"
    ,"Y"}
    Returns: { 6,  5,  4,  3,  2,  1 }
  4. {"Y................................"
    ,"................................."
    ,"................................."
    ,"................................."
    ,"................................."
    ,"................................."
    ,"................................."
    ,"................................T"}
    Returns: { 39 }
  5. {"TY"}
    Returns: { 1 }
Back to all problems