PSU Campuses
Time limit1sMemory limit128 MB
Starting and ending at Hatyai, sum the pairwise table distances along each given campus visit order.
- Level
Easy1 of 10
- Topics
- Simulation
- Solved
- No attempts yet
Problem
Prince of Songkla University (PSU) runs five campuses in the south of Thailand: Hatyai (H), Pattani (P), Suratthani (S), Phuket (K) and Trang (T). The distances between the campuses are in the table below.
When the president of PSU goes on a mission through several campuses, he or she wants to know the total distance of the mission. A mission always starts at the Hatyai campus, and once the mission ends the president returns from the last campus straight back to Hatyai.
Given the order of campuses of one mission, write a program that computes the total distance of that mission. The same campus can appear twice in a row, and then the distance between the two is 0.
Input
The first line contains the number of missions (). Each of the next lines describes one mission. A mission is given as a string made only of the characters H, P, S, K and T, and the president visits the campuses in the order written in that string. The Hatyai campus is always both the starting point and the end point, so H is not written at the beginning or at the end of the string. H can still appear as an intermediate campus. Each string has length between 1 and 10.
Output
For each mission print one line in the form Case i: d, where is the mission number starting from 1 and is the total distance of that mission in kilometres. Put exactly one space after the colon.