#K79997. Total Travel Cost Calculator
Total Travel Cost Calculator
Total Travel Cost Calculator
Given a number of travel segments and their respective directions and distances, determine the total cost of the journey. The cost per kilometer in each direction is defined as follows:
- North (N): $1 per kilometer
- South (S): $2 per kilometer
- East (E): $3 per kilometer
- West (W): $4 per kilometer
The input begins with an integer n, representing the number of travel segments, followed by n lines. Each line contains a direction (N, S, E, or W) and an integer indicating the number of kilometers traveled in that direction. Your task is to calculate and output the total travel cost.
Mathematically, if the trip consists of segments \( (d_i, k_i) \) for \( i=1,\dots,n \) and the cost per kilometer for direction \( d \) is \( c(d) \), then the total cost \( C \) is given by:
\[ C = \sum_{i=1}^{n} c(d_i) \times k_i \]inputFormat
The first line contains an integer n that denotes the number of travel segments. Each of the following n lines contains a character and an integer separated by a space. The character represents the direction (one of N, S, E, or W) and the integer represents the number of kilometers traveled in that direction.
outputFormat
Output a single integer representing the total cost of the travel journey.
## sample4
N 10
S 5
E 3
W 2
37