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>
#include<cstdlib>
using namespace std;

int charge(int in, int out);
int dist(int in, int out);
int checkhalf(int ih, int im, int oh, int om, int dis);
int half(int y);

int main(){
	int inic, inh, inm, outic, outh, outm, yen, kyori;
	while(1){
		cin >>inic;
		if(inic == 0) break;
		cin >>inh >>inm >>outic >>outh >>outm;
		
		yen = charge(inic, outic);
		kyori = dist(inic, outic);
		if(checkhalf(inh, inm, outh, outm, kyori)) yen = half(yen);
		
		cout <<yen <<endl;
	}
	return 0;
}

int charge(int in, int out){
	if(in == 1){
		if(out == 2) return 300;
		if(out == 3) return 500;
		if(out == 4) return 600;
		if(out == 5) return 700;
		if(out == 6) return 1350;
		if(out == 7) return 1650;
	} else if(in == 2){
		if(out == 3) return 350;
		if(out == 4) return 450;
		if(out == 5) return 600;
		if(out == 6) return 1150;
		if(out == 7) return 1500;
	} else if(in == 3){
		if(out == 4) return 250;
		if(out == 5) return 400;
		if(out == 6) return 1000;
		if(out == 7) return 1350;
	} else if(in == 4){
		if(out == 5) return 250;
		if(out == 6) return 850;
		if(out == 7) return 1300;
	} else if(in == 5){
		if(out == 6) return 600;
		if(out == 7) return 1150;
	} else if(in == 6){
		if(out == 7) return 500;
	} else{
		cout <<"error!";
	}
}

int dist(int in, int out){
	if(in == 1){
		if(out == 2) return 6;
		if(out == 3) return 13;
		if(out == 4) return 18;
		if(out == 5) return 23;
		if(out == 6) return 43;
		if(out == 7) return 58;
	} else if(in == 2){
		if(out == 3) return 7;
		if(out == 4) return 12;
		if(out == 5) return 17;
		if(out == 6) return 37;
		if(out == 7) return 52;
	} else if(in == 3){
		if(out == 4) return 5;
		if(out == 5) return 10;
		if(out == 6) return 30;
		if(out == 7) return 45;
	} else if(in == 4){
		if(out == 5) return 5;
		if(out == 6) return 25;
		if(out == 7) return 40;
	} else if(in == 5){
		if(out == 6) return 20;
		if(out == 7) return 35;
	} else if(in == 6){
		if(out == 7) return 15;
	} else{
		cout <<"error!";
	}
}

int checkhalf(int ih, int im, int oh, int om, int dis){
	int flag1 = 0, flag2 = 0;
	if(dis > 40) return 0;
	
	if(ih < 17 || (ih == 17 && im <= 30)){
		if((oh == 19 && om < 30) || oh < 19){
			flag1 = 1;
		}
	}
	
	if(ih > 17 || (ih == 17 && im > 30)){
		if((oh == 19 && om >= 30) || oh > 19){
			flag2 = 1;
		}
	}
	
	if((flag1 && flag2) || (!flag1 && !flag2)) return 0;
	else return 1;
}

int half(int y){
	int temp = y;
	
	temp /= 2;
	if(temp % 50 != 0){
		temp = temp + abs((temp % 50) - 50);
	}
	
	return temp;
}

C++: // 2011/03/01 Tazoe

#include <iostream>
using namespace std;

int main()
{
	int tol[8][8] = {{  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1},
	                 {  -1,   0, 300, 500, 600, 700,1350,1650},
	                 {  -1, 300,   0, 350, 450, 600,1150,1500},
	                 {  -1, 500, 350,   0, 250, 400,1000,1350},
	                 {  -1, 600, 450, 250,   0, 250, 850,1300},
	                 {  -1, 700, 600, 400, 250,   0, 600,1150},
	                 {  -1,1350,1150,1000, 850, 600,   0, 500},
	                 {  -1,1650,1500,1350,1300,1150, 500,   0}};

	int dis[8][8] = {{  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1},
	                 {  -1,   0,   6,  13,  18,  23,  43,  58},
	                 {  -1,   6,   0,   7,  12,  17,  37,  52},
	                 {  -1,  13,   7,   0,   5,  10,  30,  45},
	                 {  -1,  18,  12,   5,   0,   5,  25,  40},
	                 {  -1,  23,  17,  10,   5,   0,  20,  35},
	                 {  -1,  43,  37,  30,  25,  20,   0,  15},
	                 {  -1,  58,  52,  45,  40,  35,  15,   0}};

	while(true){
		int fic;
		cin >> fic;
		if(fic==0)
			break;

		int fh, fm;
		cin >> fh >> fm;
		int tic;
		cin >> tic;
		int th, tm;
		cin >> th >> tm;

		int fhm = fh*100+fm;
		int thm = th*100+tm;

		if(((fhm>=1730&&fhm<=1930)||(thm>=1730&&thm<=1930))&&dis[fic][tic]<=40)
			cout << (tol[fic][tic]/50+1)/2*50 << endl;
		else
			cout << tol[fic][tic] << endl;
	}

	return 0;
}

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[7] = {0,6,13,18,23,43,58},toll[8][8];
	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][3] = 350,toll[2][4] = 450,toll[2][5] = 600,toll[2][6] = 1150,toll[2][7] = 1500;
	toll[3][4] = 250,toll[3][5] = 400,toll[3][6] = 1000,toll[3][7] = 1350;
	toll[4][5] = 250,toll[4][6] = 850,toll[4][7] = 1300;
	toll[5][6] = 600,toll[5][7] = 1150;
	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);

		if(start > goal)swap(start,goal);

		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){
					ans -= (ans%50);
					ans += 50;
				}
			}
		}

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

	}

    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
long p[8][8]={{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}};
long s,e,hs,ms,he,me,a,b,c;
while(cin>>s){
if(s==0)break;
cin>>hs>>ms>>e>>he>>me;
if(s>e){a=s;s=e;e=a;}
hs*=60;hs+=ms;
he*=60;he+=me;
a=(hs-1050)*(he-1050);
b=(hs-1170)*(he-1170);
if(a<=0){if(b>0)c=1;else c=0;}
else{if(b<=0)c=1;else c=0;}
if(p[e-1][s-1]<=40&&c==1)cout<<((p[s-1][e-1]/50+1)/2)*50<<endl;
else cout<<p[s-1][e-1]<<endl;
}
return 0;
}

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,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;
}