trial -- subway transfer, -- subway Transfer

Source: Internet
Author: User

trial -- subway transfer, -- subway Transfer
[Problem]


Description: two subway lines are known, where A is the ring line and B is the east-west line. The lines are bidirectional. The names of the sites are as follows, and the interchange points of the two lines are represented by T1 and T2. Write a program, enter the names of the two sites at will, and output the minimum number of stations that need to pass by subway (including the input start and end points, and the transfer site is calculated only once ).
Subway Line A passes through the station: A1 A2 A3 A4 A5 A6 A7 A8 A9 T1 A10 A11 A12 A13 T2 A14 A15 A16 A17 A18
Subway Line B (straight line) goes through the station: B1 B2 B3 B4 B5 T1 B6 B7 B8 B9 B10 T2 B11 B12 B13 B14 B15 input: enter two different station names output: output the least number of stations passed, with the input start point and end point, the transfer site only calculates the input sample once: A1 A3 output sample: 3


[Code]
# Include <stdio. h> # include <stdlib. h> # include <string. h> int jishi3 (char * start, char * end) {int a1 [] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; // distance from line A to station T1: int a2 [] = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6 }; // distance between line A and station T2: int b1 [] = {6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; // distance from line B to station T1 int b2 [] = {12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6}; // The distance from line B to station T2 // The distance from line Achar aa [20] [5] = {"A1", "A2 ", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "T1", "A10", "A11 ", "A12", "A13", "T2", "A14", "A15", "A16", "A17", "A18 "}; // line Bchar bb [17] [5] = {"B1", "B2", "B3", "B4", "B5", "T1 ", "B6", "B7", "B8", "B9", "B10", "T2", "B11", "B12", "B13", "B14 ", "B15"}; int count = 0; int I; int tmp1, tmp2; int posS, posE; // The start and end points are all transfer station if (start [0] = 'T' & end [0] = = 'T') count = 6; // the start and end points are all on line A. else if (start [0]! = 'B' & end [0]! = 'B') {for (I = 0; I <20; I ++) {if (strcmp (start, aa [I]) = 0) posS = I; if (strcmp (end, aa [I]) = 0) posE = I;} count = 1 + (posS-posE)> 0 )? (PosS-posE): (posE-posS);} // the start and end points are all on line B else if (start [0]! = 'A' & end [0]! = 'A') {for (I = 0; I <17; I ++) {if (strcmp (start, bb [I]) = 0) posS = I; if (strcmp (end, bb [I]) = 0) posE = I;} count = 1 + (posS-posE)> 0 )? (PosS-posE): (posE-posS);} // the start and end points are respectively on two lines. else {// the start point is on line, end Point on line B if (start [0] = 'A') {for (I = 0; I <20; I ++) if (strcmp (start, aa [I]) = 0) {posS = I; break;} for (I = 0; I <17; I ++) if (strcmp (end, bb [I]) = 0) {posE = I; break ;}// start point on line B, end point on line A else {for (I = 0; I <20; I ++) if (strcmp (end, aa [I]) = 0) {posE = I; break;} for (I = 0; I <17; I ++) if (strcmp (start, bb [I]) = 0) {posS = I; brea K ;}} tmp1 = a1 [posS] + b1 [posE]; tmp2 = a2 [posS] + b2 [posE]; count = (tmp1> tmp2 )? Tmp2: tmp1)-1;} return count;} int main (void) {char start [10], end [10]; int count; scanf ("% s ", start); scanf ("% s", end); count = jishi3 (start, end); printf ("% d \ n", count); return 0 ;}



 to Vv and subway station

Bus Route: 36 → central ring road, about 19.0 km
1. Take road 36 from and go through 12 stations to the East Site of xili Hospital
2. About 290 walk, arrive at xili station, take the ring in the middle of the line, pass through 6 stations, and arrive at Wuhe station subway station to have no fear of damage on the boarding Board

Which of the following is the closest connection between the subway station and the subway station to the  station? Urgent

Sakada can take 321 to the base at sakada.
You can also take 391 or 335 to 
The subway does not directly reach .
Hope to help you.
If you have any questions, you can call 12580 for travel inquiry.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.