/*
第2種情報処理技術者試験 平成5年度・秋期・午後 問18
BohYoh Shibata PREPARATION
*/
#include <stdio.h>
#define DIRECT 15
#define SEMI_C 30
int time_req(int,int);
int minimum(int,int *);
main()
{
int st_1, st_2, tm;
printf("駅の番号:");
scanf("%d", &st_1);
printf("駅の番号:");
scanf("%d", &st_2);
tm = time_req(st_1, st_2);
printf("\n%d番と%d番の駅間の最短所要時間:%d分\n",st_1,st_2,tm);
}
int time_req(int st1,int st2)
{
static int table[][2]={{0,15},{5,25},{9,21},{19,11},{25,5},
{15,0},{23,7},{20,10},{12,18},{8,22}};
int req[4],req_min,sw,wk;
if (st1 != st2) {
if (st1 > st2) {
wk = st1;
st1 = st2;
st2 = wk;
}
sw = (st1 - 5)*(st2 - 5);
if (sw <= 0) {
req[0] = table[st1][0] + table[st2][0];
req[1] = table[st1][1] + table[st2][1];
req[2] = table[st1][0] + DIRECT + table[st2][1];
req[3] = table[st1][1] + DIRECT + table[st2][0];
req_min = minimum(4, req);
} else if (st1 < 5) {
req[0] = table[st1][0] + DIRECT + table[st2][1];
req[1] = SEMI_C - (table[st1][0] + table[st2][1]);
req_min = minimum(2,req);
} else {
req[0] = table[st1][1] + DIRECT + table[st2][0];
req[1] = SEMI_C - (table[st1][1] + table[st2][0]);
req_min = minimum(2,req);
}
} else {
req_min = 0;
}
return req_min;
}
int minimum(int n,int *req_p)
{
int i,min;
min = *req_p;
for (i = 1; i < n; i++) {
req_p++;
if (min > *req_p)
min = *req_p;
}
return min;
}