Metro Train Fare - TCS NQT

Metro Train Fare - TCS NQT 

Problem:

A metro train is a ring route train which runs in a circular fashion. There are N stations in the train's route. The names of the N stations and the distance between each station (from the previous station to the current station) are passed as the input to the program. For every 1000 meters, the ticket fare is X rupees. The name of the source station, the name of destination station and the value of X are also passed as the input to the program. The program must print the total ticket fare F as the output. The total ticket fare F must be ceiled. 

Boundary Condition(s): 

1 <= N <= 30 Length of each station's name = 2 

1 <= Distance between two stations <= 5000 1 <= X <= 25 

Input Format: The first line contains N. The second line contains the names of the N stations separated by a space. The third line contains the distance between each station separated by a space. The fourth line contains the name of the source station and the destination station separated by a space. The fifth line contains X. 

Output Format: The first line contains the total ticket fare F. 

Example Input/Output 1: 

Input: 

AB DK GH KJ OP RS XY TK 

600 800 750 900 1600 900 1400 1500 

XY KJ 

Output: 

23 

Explanation: 

The source station is XY and the destination station is KJ. The stations present between the source and the destination are XY, TK, AB, DK, GH and KJ. The distance between XY to TK is 1500 meters. The distance between TK to AB is 600 meters. The distance between AB to DK is 800 meters. The distance between DK to GH is 750 meters. The distance between GH to KJ is 900 meters. The total distance covered is 4550 meters. The total ticket cost is 22.75. After ceiling the ticket cost, it becomes 23. So 23 is printed as the output. 

Example Input/Output 2: 

Input: 

AB DK GH KJ OP RS XY TK 

600 800 750 900 1600 900 1400 1500 

RS XY 

10 

Output: 

14 

Example Input/Output 3: 

Input: 

GT XY AK VU MN 

1300 710 970 550 920 

MN GT 

Output: 

10

Program:

import math

n = int(input())

name = input().split()

fare = list(map(int,input().split()))

s, d = input().split()

x = int(input())

total_distance = 0 

pos = name.index(s)+1

while name[pos%n] != d: 

    total_distance += fare[pos%n]

    pos += 1 

total_distance += fare[pos%n]    

print(math.ceil((total_distance/1000) * x)) 

Comments

Popular posts from this blog

Pronic Integers in N - InfyTQ question

Count Strong Points - Accenture

Letters at position of multiples of a number