标签:style blog io color ar os sp for div
#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}; //线路A到T1站的距离
int a2[] = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6}; //线路A到T2站的距离
int b1[] = {6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; //线路B到T1站的距离
int b2[] = {12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6}; //线路B到T2站的距离
//线路A
char aa[20][5] = {"A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "T1", "A10", "A11", "A12", "A13", "T2", "A14", "A15", "A16", "A17", "A18"};
//线路B
char 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;
//起点终点都是换乘站
if (start[0] == 'T' && end[0] == 'T')
count = 6;
//起点终点都在线路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));
}
//起点终点都在线路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)) ;
}
//起点终点在分别在两条线路上
else {
//起点在线路A上,终点在线路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;
}
}
//起点在线路B上,终点在线路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;
break;
}
}
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;
}标签:style blog io color ar os sp for div
原文地址:http://www.cnblogs.com/mengfanrong/p/4094725.html