/*
・・・Q・・・・・・・・・・・Z・p・メ・・・ア ・ス・ャ11・N・x・E・t・・・E・゚・・ ・・7
BohYoh Shibata PREPARATION
*/
#include <math.h>
#include <string.h>
#define MAX_DIST 100
typedef struct { char *name; int dist; int rank; } STATION;
typedef struct { int dist; int cost; } FARE;
static FARE dist_fare[] = {{0, 100}, {5, 50}, {20, 40},
{40, 30}, {70, 20}, {MAX_DIST, 10}};
static double weight[] = {1.0, 1.1, 1.2, 1.5, 2.0};
int CalculateFare(char *from, char *to, STATION line[])
{
int dif, distx, farex, i;
double distf;
i = 0;
while(strcmp(from, line[i].name) != 0)
i++;
distf = line[i].dist * weight[line[i].rank];
i++;
while(strcmp(to, line[i].name) != 0){
distf += line[i].dist * weight[line[i].rank];
i++;
}
distx = ceil(distf);
farex = dist_fare[0].cost;
for(i = 1; distx > dist_fare[i - 1].dist; i++) {
if(distx <= dist_fare[i].dist)
dif = distx;
else
dif = dist_fare[i].dist;
farex += (dif - dist_fare[i - 1].dist) * dist_fare[i].cost;
}
return farex;
}
/*------------------------------------------------------------------------------
・e・X・g・v・・・O・・・
Copyright by BohYoh Shibata
------------------------------------------------------------------------------*/
#include <stdio.h>
static STATION linea[] = {{"a", 5, 0}, {"b", 6, 2}, {"c", 11, 1},
{"d", 8, 4}, {"e", 7, 3}, {"f", 0, 0}};
int main(void)
{
int fare;
fare = CalculateFare("a", "f", linea);
printf("a・w・ゥ・・f・w・ワ・ナ・フ・^・タ・ヘ%d・~・ナ・キ・B\n", fare);
return (0);
}