#K73787. Path Navigator on Coordinate Plane

    ID: 34053 Type: Default 1000ms 256MiB

Path Navigator on Coordinate Plane

Path Navigator on Coordinate Plane

You are given a series of commands that instruct a navigator to move on a two-dimensional plane. Initially, the navigator is at the origin \( (0,0) \). Each command instructs the navigator to move in one of the four cardinal directions: north (N), south (S), east (E) or west (W), by a given number of steps.

If an invalid command is provided (i.e. a direction other than N, S, E, or W), the command is ignored and the navigator remains at the current position.

After processing all commands, output the final position as two integers representing the \(x\) and \(y\) coordinates, followed by the Euclidean distance from the origin printed on a separate line. The distance should be calculated using the formula \( d = \sqrt{x^2 + y^2} \) and printed with six decimal places.

Input Format:

  • The first line contains an integer \( n \), the number of commands.
  • The next \( n \) lines each contain a command consisting of a character and an integer, separated by a space. The character represents the direction ('N', 'S', 'E', 'W') and the integer represents the number of steps.
  • Output Format:

    • Output two integers in one line representing the final \(x\) and \(y\) coordinates, separated by a space.
    • Output the Euclidean distance from the origin on the next line, formatted to six decimal places.
    • inputFormat

      The input starts with a single integer \( n \), denoting the number of commands. The following \( n \) lines each contain a command consisting of a direction (a single character) and an integer number of steps. If the direction is not one of 'N', 'S', 'E', or 'W', it should be ignored.

      outputFormat

      First, print the final coordinates \( x \) and \( y \) (separated by a space) after executing all valid commands. Then, print on a new line the Euclidean distance from the origin \( (0,0) \) formatted with six decimal places.

      The Euclidean distance is defined as \( d = \sqrt{x^2 + y^2} \).

      ## sample
      0
      
      0 0
      

      0.000000

      </p>