Commuter Trains

The manager of Sants station has designed a system for assigning arriving commuter trains to the station’s tracks. There are four commuter rail lines, 1, 2, 3, and 4, and two possible directions: ”N” (north) and ”S” (south). The track assignments are as follows. For line 1, northbound trains use track 8 and southbound trains use track 7. For line 2, the tracks are 10 (north) and 9 (south). For line 3, the tracks are 12 (north) and 13 (south). Finally, for line 4, the tracks are 14 (north) and 15 (south).

Design the function cercanias(linea,sentido), which takes a positive integer linealinea representing the commuter rail line and a character sentidosentido indicating the direction (”N” for north and ”S” for south), and returns the corresponding track number. If the line or direction is invalid, the function must return 0.

Sample session

Problem information

Author: Unknown
Translator: infbesos

Generation: 2026-10-13T21:52:46.939Z

© Jutge.org, 2006–2026.
https://jutge.org