1108 - Rectangular Polygons

Time Limit: 1s Memory Limit: 128MB

Submissions: 16 Solved: 9
Description
In this problem, we will help the Faculty of Civil Engineering. They need a software to analyze ground plans of buildings. Specifically, your task is to detect outlines of a building when all of its corners are given. You may assume that each building is a rectangular polygon with each of its sides being parallel either with X or Y axis. Therefore, each of its vertex angles is exactly either 90 or 270 degrees.
Input
The input contains several buildings. The description of each building starts with a single positive integer N, the number of corners (polygon vertices), 1 ≤ N ≤ 1000. Then there are N pairs of integer numbers Xi, Yi giving coordinates of individual corners, |Xi|, |Yi| ≤ 10 000. You may assume that all corners are listed and no two of them have the same coordinates. The polygon does always exist, it is closed, its sides do not intersect or touch (except neighboring sides, of course), and it contains no “holes” inside. In other words, the outline is formed by one closed line. The order of corners in the input file may be arbitrary. There is an empty line after each building, then the next one is described. After the last building, there is a single zero that signals the end of input.
Output
For each building, output one line containing N characters without any whitespace between them. The characters should be uppercase letters that specify directions of individual walls (sides) when the building outline is followed. “N” stands for North (the positive direction of the Y axis), “E” for East (the positive direction of the X axis), “W” for West, and “S” for South. The “walk” should start in the vertex that has been given first in the input and always proceed in the clockwise direction.
Sample Input
4
0 0
2 2
0 2
2 0
6
1 1
2 2
0 1
1 0
0 2
2 0
0
Sample Output
NESW
WNESWN
Hint
The second sample input corresponds to the picture.
Source
Central Europe Regional Contest 2007