Statistics

Problem Statement for "Surveyor"

Problem Statement

*** You may only submit a given problem once - no resubmissions will be accepted. ***

A plot has been surveyed. Its boundary consists of segments that form a polygon. Each segment runs either North-South or East-West. Create a class Surveyor that contains a method area that takes as input a String direction and a int[] length and returns the enclosed area.

The i-th character of direction and the i-th element of length describe the direction and length of the i-th segment of the polygon's boundary as the surveyor walked it. If you start at the surveyor's starting point and walk according to the sequence of directions and lengths reported by the surveyor, you will traverse the boundary of the polygon, ending up back at the starting point. This traversal described by the given segments may be either clockwise or counterclockwise.

Definition

Class:
Surveyor
Method:
area
Parameters:
String, int[]
Returns:
int
Method signature:
int area(String direction, int[] length)
(be sure your method is public)

Constraints

  • direction will have between 4 and 50 characters inclusive.
  • length will have the same number of elements as the number of characters in direction.
  • Each element of direction will be an uppercase letter 'N', 'E', 'S', or 'W'.
  • Each element of length will be between 1 and 1000 inclusive.
  • The segments will represent a simple polygon. No two segments will touch or intersect (except that the last point of a segment is the first point of the next segment, and the last point of the final segment is the first point of the first segment).

Examples

  1. "NWWSE"

    {10,3,7,10,10}

    Returns: 100

    This plot is a 10 x 10 square.

  2. "NESWNWSW"

    {20,200,30,100,20,30,10,70}

    Returns: 4700

    ___________________ | __ | |______| | | S |_________| The S indicates the Start/End point of the traversal.

  3. "NWSESWNESWNE"

    {4,4,2,1,1,2,4,6,7,7,2,6}

    Returns: 28

  4. "NENESSSW"

    {2,1,2,1,1,1,2,2}

    Returns: 6

  5. "EEEEEEEEEEEESSSSSSSSSSSSSWWWWWWWWWWWWNNNNNNNNNNNNN"

    {1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000}

    Returns: 156000000

  6. "NNNNWSSSSE"

    {100,200,200,200,921,100,200,200,200,921}

    Returns: 644700

  7. "SSSSWNNNNE"

    {100,200,200,200,921,100,200,200,200,921}

    Returns: 644700

  8. "NWSENWSWNESE"

    {1000,995,990,985,975,965,955,10,969,984,999,1}

    Returns: 952959

  9. "NWSENWSWNESSE"

    {1000,995,990,985,975,965,955,10,969,984,400,599,1}

    Returns: 952959

  10. "NWSENWSWNESSWNNEESSW"

    {1000,995,990,985,975,965,955,10,969,984,400,599,999,1,1000,1,1000,500,501,1}

    Returns: 49042

  11. "NESWNE"

    {3,3,5,5,2,2}

    Returns: 19

  12. "WNWSENWSWNESSWNNEESS"

    {1,1000,995,990,985,975,965,955,10,969,984,400,599,999,1,1000,1,1000,500,501}

    Returns: 49042

  13. "ENWSWNESWNES"

    {4,4,2,1,1,2,4,6,7,7,2,6}

    Returns: 28

  14. "SENWNESWNESW"

    {4,4,2,1,1,2,4,6,7,7,2,6}

    Returns: 28

  15. "WSENESWNESWN"

    {4,4,2,1,1,2,4,6,7,7,2,6}

    Returns: 28

  16. "WSWNNEEEEESSSWNWSWNN"

    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}

    Returns: 11


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: