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 <iostream>
using namespace std;

int abs(int i)
{
  return ( i < 0 ? -i : i );
}
int km_to_yen(int km)
{
  switch(km)
  {
  case 5:
    return 250;
  case 6:
    return 300;
  case 7:
    return 350;
  case 10:
    return 400;
  case 12:
    return 450;
  case 13:
  case 15:
    return 500;
  case 17:
  case 18:
  case 20:
    return 600;
  case 23:
    return 700;
  case 25:
    return 850;
  case 30:
    return 1000;
  case 35:
  case 37:
    return 1150;
  case 40:
    return 1300;
  case 43:
  case 45:
    return 1350;
  case 52:
    return 1500;
  case 58:
    return 1650;
  }
}

int main()
{
  int ic_km[8] = { 0, 0, 6, 13, 18, 23, 43, 58, };
  while (true)
  {
    int from_num;
    int from_hour, from_min;
    cin >> from_num;
    if ( from_num == 0 ) break;
    cin >> from_hour >> from_min;
    int from_time = from_hour*100 + from_min;

    int to_num;
    int to_hour, to_min;
    cin >> to_num;
    cin >> to_hour >> to_min;
    int to_time = to_hour*100 + to_min;

    int km_diff = abs(ic_km[to_num] - ic_km[from_num]);
    int fare = km_to_yen(km_diff);
    if ( ( ( 1730 <= from_time && from_time <= 1930 ) ||
           ( 1730 <= to_time   && to_time   <= 1930 ) ) &&
         ( km_diff < 40 ) )
    {
      fare /= 2;
      if ( fare % 50 != 0 )
      {
        fare = ( fare / 50 + 1 ) * 50;
      }
    }
    cout << fare << endl;
  }
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#define NN 1000
using namespace std;

int main(){
  int aa[8][8]={{0,1,2,3,4,5,6,7},
		{1,0,300,500,600,700,1350,1650},
		{2,6,0,350,450,600,1150,1500},
		{3,13,7,0,250,400,1000,1350},
		{4,18,12,5,0,250,850,1300},
		{5,23,17,10,5,0,600,1150},
		{6,43,37,30,25,20,0,500},
		{7,58,52,45,40,35,15,0}};
  int i,j,n,time00,time01,time10,time11,n2,disc,mo;
  int disc2;
  while(1){
    disc2=0;
    disc=0; //flag
    cin >> n;
    if(n == 0)break;
    cin >> time00 >> time01;
    cin >> n2;
    cin >> time10 >> time11;

    //  cout << aa[n2][n] << endl;
    // cout << time[1][0] <<" " <<time[1][1] << endl; 
    //if(time10>=17 && (time10 <=19)){
      if(time10 == 19 && time11 <= 30){disc2=1;}
      else if(time10 == 18)disc2=1;
      else if(time10 == 17 && time11>=30)disc2=1;
      // cout << "tes" << endl;
      if(aa[n2][n]<=40 && disc2==1)disc=1; //ツ湘ーツ個渉づーツ鳴楪つスツつオツづつ「ツづェツづ仕iscountツフツδ可グON
      // cout << "tes" << endl;
      //}

    mo=aa[n][n2];
    if(disc == 1){
      mo=mo/2;
      disc=0;
      if(mo%50 !=0)mo=mo+25;
    }
    cout << mo << endl;


    }


}

C++: #include<cmath>
#include<algorithm>
using namespace std;
int hyo[7][7]={
	{0,300,500,600,700,1350,1650},
	{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,0}
};
int main(){
	int s,g, h,m,H,M, c;
	while(cin>>s,s){
		cin>>h>>m>>g>>H>>M;
		if(s>g)swap(s,g);
		c=hyo[s-1][g-1];
		if(hyo[g-1][s-1]<=40 &&( (1050<=h*60+m&&h*60+m<=1170)||(1050<=H*60+M&&H*60+M<=1170) ) )
		c=((int)ceil((c/2/50.0)))*50;
		cout<<c<<endl;
	}
	return 0;
}