Your task is to format an address given in all lowercase to a friendlier format. Here's the catch, no regexes.
Addresses will be given in the following format:
123 serpentine pl ne shoreline wa 98199
The expected output is the following: (notice the period and commas)
123 Serpentine Pl. NE, Shoreline WA, 98199
Formatting Rules
Cardinal directions should be capitalized, e.g. "e" --> "E", "nw" --> "NW".
Abbreviations for streets, avenues, etc. should have the first letter capitalized with the abbr. followed by a period (".") e.g "st" --> "St.", "ave" --> "Ave.".
State abbreviation should be in all caps
A comma is placed after each section. i.e. after the street address and state and city.
Capitalize the city and street/avenue/place.
EDIT: Addresses will always be given in the above format except with or without a cardinal direction.
Your code should also be able to handle "st" and "ave". The input is given through stdin
. This is code-golf so the shortest code in bytes wins.
st
ave
pl
things? \$\endgroup\$ – mniip Mar 26 '14 at 7:00<number> <street> <st/ave/pl> <direction> <city> <state> <zip>
? Or may parts be omitted (e.g. can the address not have a St/Ave/Pl postfix, or a cardinal direction). \$\endgroup\$ – CompuChip Mar 26 '14 at 7:08123 Serpentine Place NE, Shoreline Washington 98199
or123 Serpentine Pl NE, Apartment 6, Shoreline Wa 98199
or123 Serpentine Pl, 98199
. How do we handle those, or are we to only expect addresses strictly in the formats already given without any more or less detail? \$\endgroup\$ – Iszi Mar 26 '14 at 20:07