Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	distance_table := [][]int{
		{0, 6, 13, 18, 23, 43, 58},
		{6, 0, 7, 12, 17, 37, 52},
		{13, 7, 0, 5, 10, 30, 45},
		{18, 12, 5, 0, 5, 25, 40},
		{23, 17, 10, 5, 0, 20, 35},
		{43, 37, 30, 25, 20, 0, 15},
		{58, 52, 45, 40, 35, 15, 0},
	}
	toll_table := [][]int{
		{0, 300, 500, 600, 700, 1350, 1650},
		{300, 0, 350, 450, 600, 1150, 1500},
		{500, 350, 0, 250, 400, 1000, 1350},
		{600, 450, 250, 0, 250, 850, 1300},
		{700, 600, 400, 250, 0, 600, 1150},
		{1350, 1150, 1000, 850, 600, 0, 500},
		{1650, 1500, 1350, 1300, 1150, 500, 0},
	}
	for scanner.Scan() {
		d, _ := strconv.Atoi(scanner.Text())
		if d == 0 {
			break
		}
		d--
		scanner.Scan()
		dbuf := strings.Split(scanner.Text(), " ")
		dh, _ := strconv.Atoi(dbuf[0])
		dm, _ := strconv.Atoi(dbuf[1])
		dtime := 100*dh+dm
		scanner.Scan()
		a, _ := strconv.Atoi(scanner.Text())
		a--
		scanner.Scan()
		abuf := strings.Split(scanner.Text(), " ")
		ah, _ := strconv.Atoi(abuf[0])
		am, _ := strconv.Atoi(abuf[1])
		atime := 100*ah+am
		toll := toll_table[d][a]
		if distance_table[d][a] <= 40 &&
			1730 <= dtime && dtime <= 1930 ||
			1730 <= atime && atime <= 1930 {
				toll = ((toll/2-1)/50+1)*50
		}
		fmt.Println(toll)
	}
}

C++: #include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>

using namespace std;

int main(){

	int start,goal,start_h,start_m,goal_h,goal_m,ans;
	int dist[8] = {0,0,6,13,18,23,43,58},toll[8][8];
	toll[1][1] = 0,toll[1][2] = 300,toll[1][3] = 500,toll[1][4] = 600,toll[1][5] = 700,toll[1][6] = 1350,toll[1][7] = 1650;
	toll[2][2] = 0,toll[2][3] = 350,toll[2][4] = 450,toll[2][5] = 600,toll[2][6] = 1150,toll[2][7] = 1500;
	toll[3][3] = 0,toll[3][4] = 250,toll[3][5] = 400,toll[3][6] = 1000,toll[3][7] = 1350;
	toll[4][4] = 0,toll[4][5] = 250,toll[4][6] = 850,toll[4][7] = 1300;
	toll[5][5] = 0,toll[5][6] = 600,toll[5][7] = 1150;
	toll[6][6] = 0,toll[6][7] = 500;

	while(true){
		scanf("%d",&start);
		if(start == 0)break;

		scanf("%d %d",&start_h,&start_m);

		scanf("%d",&goal);
		scanf("%d %d",&goal_h,&goal_m);

		ans = toll[start][goal];

		if(dist[goal]-dist[start] <= 40){
			if((start_h*60+start_m) >= 17*60+30 || (goal_h*60+goal_m) <= 19*60+30){
				ans /= 2;
				if(ans%50 > 0){
					while(ans % 50 != 0)ans++;
				}
			}
		}

		printf("%d\n",ans);

	}

    return 0;
}

C++: #include<iostream>
#define S 1050 //1050min = 17:30 //
#define G 1170 //1170min = 19:30 //
using namespace std;
int kiriage(int);
int main(){
	int tmp[7][7]={{0,300,500,600,700,1350},
								{6,0,350,450,600,1150,1500},
								{13,7,0,250,400,1000,1350},
								{18,12,5,0,250,850,1300},
								{23,17,10,5,0,600,1150},
								{43,37,30,25,20,0,500},
								{58,52,45,40,35,15}};

	int sIC,sh,sm,gIC,gh,gm,smin,gmin,cost;
	while(cin >> sIC && sIC){
		cin >> sh >> sm >> gIC >> gh >> gm;
		smin = sh * 60 + sm;
		gmin = gh * 60 + gm;
		cout << (((smin >= S && smin <= G) || (gmin >= S && gmin <= G)) ?
			 		kiriage(tmp[sIC-1][gIC-1]/2) : tmp[sIC-1][gIC-1]) << endl;
	}
}
int kiriage(int cost){
	return (cost%50==0 ? cost : cost / 50 * 50 + 50);
}

C++: #include <iostream>
using namespace std;
int main(){
	int discount[2]={17*60+30,19*60+30};
	int D[7]={0,6,13,18,23,43,58};
	int C[7][7]={
		{0,300,500,600,700,1350,1650},
		{0,0,350,450,600,1150,1500},
		{0,0,0,250,400,1000,1350},
		{0,0,0,0,250,850,1300},
		{0,0,0,0,0,600,1150},
		{0,0,0,0,0,0,500},
	};
	int in,out;
	while(cin>>in,in){
		int h1,m1,h2,m2,fare;
		cin>>h1>>m1;
		cin>>out;
		cin>>h2>>m2;
		if(in>out){
			int tmp=in;
			in=out;
			in=tmp;
		}
		int d=D[out-1]-D[in-1];
		int min1=h1*60+m1;
		int min2=h2*60+m2;
		if((discount[0]<=min1&&min1<=discount[1])||(discount[0]<=min2&&min2<=discount[1])&&d<=40) fare=(C[in-1][out-1]/2+49)/50*50;
		else fare=C[in-1][out-1];
		cout<<fare<<endl;
	}
	return 0;
}

C++: #include<iostream>
#define N 7

using namespace std;

int cost[N][N];
int dis[N][N];

void InitCost(){
  for(int i=0; i<N; i++) cost[i][i] = 0;

  cost[0][1] = 300;
  cost[0][2] = 500;
  cost[0][3] = 600;
  cost[0][4] = 700;
  cost[0][5] = 1350;
  cost[0][6] = 1650;

  cost[1][2] = 350;
  cost[1][3] = 450;
  cost[1][4] = 600;
  cost[1][5] = 1150;
  cost[1][6] = 1500;

  cost[2][3] = 250;
  cost[2][4] = 400;
  cost[2][5] = 1000;
  cost[2][6] = 1350;

  cost[3][4] = 250;
  cost[3][5] = 850;
  cost[3][6] = 1300;

  cost[4][5] = 600;
  cost[4][6] = 1150;

  cost[5][6] = 500;

  cost[1][0] = 300;
  cost[2][0] = 500;
  cost[3][0] = 600;
  cost[4][0] = 700;
  cost[5][0] = 1350;
  cost[6][0] = 1650;

  cost[2][1] = 350;
  cost[3][1] = 450;
  cost[4][1] = 600;
  cost[5][1] = 1150;
  cost[6][1] = 1500;

  cost[3][2] = 250;
  cost[4][2] = 400;
  cost[5][2] = 1000;
  cost[6][2] = 1350;

  cost[4][3] = 250;
  cost[5][3] = 850;
  cost[6][3] = 1300;

  cost[5][4] = 600;
  cost[6][4] = 1150;

  cost[6][5] = 500;
}

void InitDistance(){
  for(int i=0; i<N; i++) dis[i][i] = 0;

  dis[0][1] = 6;
  dis[0][2] = 13;
  dis[0][3] = 18;
  dis[0][4] = 23;
  dis[0][5] = 43;
  dis[0][6] = 58;

  dis[1][2] = 7;
  dis[1][3] = 12;
  dis[1][4] = 17;
  dis[1][5] = 37;
  dis[1][6] = 52;

  dis[2][3] = 5;
  dis[2][4] = 10;
  dis[2][5] = 30;
  dis[2][6] = 45;

  dis[3][4] = 5;
  dis[3][5] = 25;
  dis[3][6] = 40;

  dis[4][5] = 20;
  dis[4][6] = 35;

  dis[5][6] = 15;

  dis[1][0] = 6;
  dis[2][0] = 13;
  dis[3][0] = 18;
  dis[4][0] = 23;
  dis[5][0] = 43;
  dis[6][0] = 58;

  dis[2][1] = 7;
  dis[3][1] = 12;
  dis[4][1] = 17;
  dis[5][1] = 37;
  dis[6][1] = 52;

  dis[3][2] = 5;
  dis[4][2] = 10;
  dis[5][2] = 30;
  dis[6][2] = 45;

  dis[4][3] = 5;
  dis[5][3] = 25;
  dis[6][3] = 40;

  dis[5][4] = 20;
  dis[6][4] = 35;

  dis[6][5] = 15;
}

int HighwayToll(int n, int h1, int m1, int m, int h2, int m2){
  int ans;
  ans = cost[n][m];

  if(dis[n][m] <= 40){
    if(((h1 < 17 || (h1 == 17 && m1 <= 30)) &&
	(h2 < 19 || (h2 == 19 && m2 <= 30))) ||
       ((h1 > 17 || (h1 == 17 && m1 >= 30)) &&
	(h2 > 19 || (h2 == 19 && m2 >= 30)))){
      ans /= 2;
      if(ans%50 != 0) ans = ans - ans%50 + 50;
    }
  }
  return ans;
}

int main(){
  int n, m;
  int h1, m1, h2, m2;

  InitCost();
  InitDistance();

  while(1){
    cin >> n;
    if(n == 0) break;
    cin >> h1 >> m1;
    cin >> m;
    cin >> h2 >> m2;
    --n;
    --m;
    cout << HighwayToll(n, h1, m1, m, h2, m2) << endl;
  }
  return 0;
}

C++: #include <map>
#include <cstdio>
main(){std::map<int,int>z={{12,6},{13,10},{14,12},{15,14},{16,27},{17,33},{23,7},{24,9},{25,12},{26,23},{27,30},{34,5},{35,8},{36,20},{37,27},{45,5},{46,17},{47,26},{56,12},{57,23},{67,10}};for(int a,b,h,m,H,M;scanf("%d%d%d%d%d%d",&a,&h,&m,&b,&H,&M)>5;printf("%d\n",(h+H)*50))if(m+=h*60,M+=H*60,h=z[a*10+b],H=0,h<27&&((1050<=m&&m<=1170)||(1050<=M&&M<=1170)))H=(h&1),h/=2;}