Go: package main

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

var points [5][5][4]bool

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for i := 0; i < 9; i++ {
		y := i/2
		if i%2 == 0 {
			scanner.Scan()
			info := strings.Split(scanner.Text(), "")
			for k := range info {
				e, _ := strconv.Atoi(info[k])
				if e != 0 {
					points[y][k][1], points[y][k+1][3] = true, true
				}
			}
		} else {
			scanner.Scan()
			info := strings.Split(scanner.Text(), "")
			for k := range info {
				e, _ := strconv.Atoi(info[k])
				if e != 0 {
					points[y][k][2], points[y+1][k][0] = true, true
				}
			}
		}
	}
	x := 1
	y := 0
	dir := 1
	dx := []int{0, 1, 0, -1}
	dy := []int{-1, 0, 1, 0}
	ds := "URDL"
	fmt.Printf("%s", string(ds[dir]))
	for !(x == 0 && y == 0) {
		if points[y][x][(dir+3)%4] {
			dir = (dir+3)%4
		} else if points[y][x][dir] {

		} else if points[y][x][(dir+1)%4] {
			dir = (dir+1)%4
		} else {
			dir = (dir+2)%4
		}
		x += dx[dir]
		y += dy[dir]
		fmt.Printf("%s", string(ds[dir]))
	}
	fmt.Println()
}

C++: #include<iostream>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const int N=6;
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};
const string op="RDLU";
enum{RIGHT=0,DOWN,LEFT,UP};
int m[N][N];
bool e[N][N][N];


string solve(){
  int y=0,x=1,r=RIGHT;
  string ret="";
  do{
    bool a=true;
    if (!e[y][x][(r+1)%4])r=(r+1)%4;
    while(e[y][x][r])ret+=op[r],r=(r+3)%4;
    if (e[y][x][(r+1)%4])ret+=op[r];
    y+=dy[r];
    x+=dx[r];
  }while(y != 0 || x != 1);
  return ret;
}

main(){
  rep(i,N)rep(j,N)rep(k,4)e[i][j][k]=false;
  rep(i,5){
    string tmp;
    cin>>tmp;
    rep(j,4)if (tmp[j] == '1')e[i][j+1][DOWN]=e[i+1][j+1][UP]=true;
    if (i == 4)break;
    cin>>tmp;
    rep(j,5)if (tmp[j] == '1')e[i+1][j][RIGHT]=e[i+1][j+1][LEFT]=true;
  }
  cout << solve() << endl;
}

C++: #include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef vector <string> VS;
const int size = 9;

int main() {
    VS lines( size );
    for ( int i = 0; i < size; ++ i ) {
        cin >> lines[i];
    }

    bool O[size + 5][size + 5];
    for ( int i = 0; i < size + 5; ++ i ) {
        for ( int j = 0; j < size + 5; ++ j ) {
            O[i][j] = false;
        }
    }
    for ( int i = 0; i < size; ++ i ) {
        for ( int j = 0; j < ( i % 2 == 0 ? 4 : 5 ); ++ j ) {
            O[i+2][j+2] = ( lines[i][j] == '1' );
        }
    }

    const string T  = "RDLU";
    const int R = 0;
    const int D = 1;
    const int L = 2;
    const int U = 3;
    int r = 2;
    int c = 2;
    int s = R;

    while ( true ) {
        putchar( T[s] );
        if ( r == 2 && c == 2 && s != R ) break;

        if ( s == L ) {
            if ( O[r + 1][c] ) {
                ++ r;
                s = D;
            } else if ( O[r][c - 1] ) {
                -- c;
                s = L;
            } else if ( O[r - 1][c] ) {
                -- r;
                s = U;
            } else if ( O[r][c + 1] ) {
                ++ c;
                s = R;
            }
        } else if ( s == R ) {
            if ( O[r - 1][c + 1] ) {
                -- r;
                ++ c;
                s = U;
            } else if ( O[r][c + 1] ) {
                ++ c;
                s = R;
            } else if ( O[r + 1][c + 1] ) {
                ++ r;
                ++ c;
                s = D;
            } else if ( O[r][c - 1] ) {
                -- c;
                s = L;
            }
        } else if ( s == U ) {
            if ( O[r - 1][c - 1] ) {
                -- r;
                -- c;
                s = L;
            } else if ( O[r - 2][c] ) {
                r -= 2;
                s = U;
            } else if ( O[r - 1][c] ) {
                -- r;
                s = R;
            } else if ( O[r + 2][c] ) {
                r += 2;
                s = D;
            }
        } else if ( s == D ) {
            if ( O[r + 1][c] ) {
                ++ r;
                s = R;
            } else if ( O[r + 2][c] ) {
                r += 2;
                s = D;
            } else if ( O[r + 1][c - 1] ) {
                ++ r;
                -- c;
                s = L;
            } else if ( O[r - 2][c] ) {
                r -= 2;
                s = U;
            }
        }
    }
    
    return 0;
}

C++: #include "stdio.h"
#include "math.h"

#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
using namespace std;
typedef long long  ll;

/** Problem0037 : Path on a Grid **/
int main()
{
	bool wall[6][6][4]={0};
	string s;
	int y=1;
	rep(k, 9) {
		cin >> s;
		if (s.length()==4) {
			rep(x, 4) {
				if (s[x]=='1') {
					wall[x+1][y-1][3]=true;
					wall[x+1][y][2]=true;
				}
			}
		} else if (s.length()==5) {
			REP(x, 1, 6) {
				if (s[x-1]=='1') {
					wall[x-1][y][1]=true;
					wall[x][y][0]=true;
				}
			}
			y++;
		}
	}
	
	int x=1, d=1; y=0;
	cout << "R";
	while (1) {
		switch (d) {
			case 1:
				if (wall[x][y][1]) {
					if (wall[x][y][2]) {
						d=0;
						cout << "U";
					} else {
						y--; d=2;
						cout << "RU";
					}
				} else if (wall[x+1][y][3]) {
					x++; d=1;
					cout << "R";
				} else if (wall[x][y+1][1]) {
					y++; x++; d=3;
					cout << "D";
				} else {
					y++; d=0;
				} break;
				
			case 3:
				if (wall[x][y][3]) {
					if (wall[x][y][1]) {
						d=2;
						cout << "R";
					} else {
						x++; d=1;
						cout << "DR";
					}
				} else if (wall[x][y+1][0]) {
					y++; d=3;
					cout << "D";
				} else if (wall[x-1][y][3]) {
					x--; y++; d=0;
					cout << "L";
				} else {
					x--; d=2;
				} break;
				
			case 0:
				if (wall[x][y][0]) {
					if (wall[x][y][3]) {
						d=1;
						cout << "D";
					} else {
						y++; d=3;
						cout << "LD";
					}
				} else if (wall[x-1][y][2]) {
					x--; d=0;
					cout << "L";
				} else if (wall[x][y-1][0]) {
					x--; y--; d=2;
					cout << "U";
				} else {
					y--; d=1;
				} break;
				
			case 2:
				if (wall[x][y][2]) {
					if (wall[x][y][0]) {
						d=3;
						cout << "L";
					} else {
						x--; d=0;
						cout << "UL";
					}
				} else if (wall[x][y-1][1]) {
					y--; d=2;
					cout << "U";
				} else if (wall[x+1][y][2]) {
					x++; y--; d=1;
					cout << "R";
				} else {
					x++; d=3;
				} break;
		}
		cout << flush;
		if (d==2 && x==0 && y==1)
			break;
		if (d==0 && x==1 && y==1) {
			cout << "L";
			break;
		}
	}
	cout << endl;
	return 0;
}