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>

#define	E	0
#define	N	1
#define	W	2
#define	S	3

using namespace std;

int wall_v[5][5];	// wall_v[a][b] : æañ ã©çbÔÚÌÇª é©Ç¤© ([a][4]ÍíÉ0)
int wall_h[5][5];	// wall_h[a][b] : æas ¶©çbÔÚÌÇª é©Ç¤© ([a][4]ÍíÉ0)

bool isRightWall(int x,int y,int dir){
	if(dir==N)	y--;
	if(dir==W)	x--;
	if(y<0 || 4<y || x<0 || 4<x)	return false;

	if(dir==E)	return wall_h[y][x];
	if(dir==N)	return wall_v[x][y];
	if(dir==W)	return wall_h[y][x];
	if(dir==S)	return wall_v[x][y];
}

bool isForwardWall(int x,int y,int dir){
	if(dir==E)	y--;
	if(dir==N)	x--;
	if(y<0 || 4<y || x<0 || 4<x)	return false;

	if(dir==E)	return wall_v[x][y];
	if(dir==N)	return wall_h[y][x];
	if(dir==W)	return wall_v[x][y];
	if(dir==S)	return wall_h[y][x];
}

void goRight(int &x,int &y,int &dir){
	if(dir==E)	y++;
	if(dir==N)	x++;
	if(dir==W)	y--;
	if(dir==S)	x--;
	dir=(dir+3)%4;
}

void goForward(int &x,int &y,int &dir){
	if(dir==E)	x++;
	if(dir==N)	y--;
	if(dir==W)	x--;
	if(dir==S)	y++;
}

void goLeft(int &x,int &y,int &dir){
	if(dir==E)	y--;
	if(dir==N)	x--;
	if(dir==W)	y++;
	if(dir==S)	x++;
	dir=(dir+1)%4;
}

int main()
{
	for(int i=0;i<9;i++){
		char s[8];	cin>>s;
		if(i%2==0){
			for(int j=0;j<4;j++)	wall_h[i/2][j]=s[j]-'0';
		}
		else{
			for(int j=0;j<5;j++)	wall_v[j][i/2]=s[j]-'0';
		}
	}

	int x=0,y=0,dir=0;
	do{
		if(!isForwardWall(x,y,dir)){
			if(!isRightWall(x,y,dir))	goRight(x,y,dir);
			else						goForward(x,y,dir);
		}
		else							goLeft(x,y,dir);

		switch(dir){
			case E:	cout<<'R';	break;
			case N:	cout<<'U';	break;
			case W:	cout<<'L';	break;
			case S:	cout<<'D';	break;
		}
	}while(!(x==0&&y==0));
	cout<<endl;

	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;

typedef vector <string> VS;

VS R;
string D = "RDLU";
const int RIGHT = 0;
const int DOWN = 1;
const int LEFT = 2;
const int UP = 3;
int cnt[100][100];

void dfs( int dir, int x, int y, int a ) {
    // cout << dir << ", " << x << ", " << y << endl;
    cout << D[dir];
    if ( x == 0 && y == 0 && cnt[y][x] > 1 ) return;
    if ( x == 0 && y == 1 && dir == UP ) return;

    if ( dir == RIGHT ) {
        // 0:ue, 1:sita
        if ( a == 0 ) {
            if ( y-1 >= 0 && x+1 < R[y-1].size() && R[y-1][x+1] == '1' ) {
                return dfs( UP, x+1, y-1, 0 );
            }
            if ( x+1 < R[y].size() && R[y][x+1] == '1' ) {
                return dfs( RIGHT, x+1, y, 0 );
            }
            if ( y+1 < R.size() && x+1 < R[y+1].size() && R[y+1][x+1] == '1' ) {
                return dfs( DOWN, x+1, y+1, 1 );
            }
        } else {
            if ( y+1 < R.size() && x+1 < R[y+1].size() && R[y+1][x+1] == '1' ) {
                return dfs( DOWN, x+1, y+1, 0 );
            }
            if ( x+1 < R[y].size() && R[y][x+1] == '1' ) {
                return dfs( RIGHT, x+1, y, 1 );
            }
            if ( y-1 >= 0 && x+1 < R[y-1].size() && R[y-1][x+1] == '1' ) {
                return dfs( UP, x+1, y-1, 1 );
            }
        }
    } else if ( dir == DOWN ) {
        // 0:hidari, 1:migi
        if ( a == 0 ) {
            if ( y+1 < R.size() && x-1 >= 0 && R[y+1][x-1] == '1' ) {
                return dfs( LEFT, x-1, y+1, 0 );
            }
            if ( y+2 < R.size() && R[y+2][x] == '1' ) {
                return dfs( DOWN, x, y+2, 0 );
            }
            if ( y+1 < R.size() && x < R[y+1].size() && R[y+1][x] == '1' ) {
                return dfs( RIGHT, x, y+1, 1 );
            }
        } else {
            if ( y+1 < R.size() && x < R[y+1].size() && R[y+1][x] == '1' ) {
                return dfs( RIGHT, x, y+1, 0 );
            }
            if ( y+2 < R.size() && R[y+2][x] == '1' ) {
                return dfs( DOWN, x, y+2, 1 );
            }
            if ( y+1 < R.size() && x-1 >= 0 && R[y+1][x-1] == '1' ) {
                return dfs( LEFT, x-1, y+1, 1 );
            }
        }
    } else if ( dir == LEFT ) {
        // 0:ue, 1:sita
        if ( a == 0 ) {
            if ( y-1 >= 0 && x < R[y-1].size() && R[y-1][x] == '1' ) {
                return dfs( UP, x, y-1, 1 );
            }
            if ( x-1 >= 0 && R[y][x-1] == '1' ) {
                return dfs( LEFT, x-1, y, 0 );
            }
            if ( y+1 < R.size()&& x < R[y+1].size() && R[y+1][x] == '1' ) {
                return dfs( DOWN, x, y+1, 0 );
            }
        } else {
            if ( y+1 < R.size()&& x < R[y+1].size() && R[y+1][x] == '1' ) {
                return dfs( DOWN, x, y+1, 1 );
            }
            if ( x-1 >= 0 && R[y][x-1] == '1' ) {
                return dfs( LEFT, x-1, y, 1 );
            }
            if ( y-1 >= 0 && x < R[y-1].size() && R[y-1][x] == '1' ) {
                return dfs( UP, x, y-1, 0 );
            }
        }
    } else if ( dir == UP ) {
        // 0:hidari, 1:migi
        if ( a == 0 ) {
            if ( y-1 >= 0 && x-1 >= 0 && R[y-1][x-1] == '1' ) {
                return dfs( LEFT, x-1, y-1, 1 );
            }
            if ( y-2 >= 0 && R[y-2][x] == '1' ) {
                return dfs( UP, x, y-2, 0 );
            }
            if ( y-1 >= 0 && x < R[y-1].size() && R[y-1][x] == '1' ) {
                return dfs( RIGHT, x, y-1, 0 );
            }
        } else {
            if ( y-1 >= 0 && x < R[y-1].size() && R[y-1][x] == '1' ) {
                return dfs( RIGHT, x, y-1, 1 );
            }
            if ( y-2 >= 0 && R[y-2][x] == '1' ) {
                return dfs( UP, x, y-2, 1 );
            }
            if ( y-1 >= 0 && x-1 >= 0 && R[y-1][x-1] == '1' ) {
                return dfs( LEFT, x-1, y-1, 0 );
            }
        }
    }
}

int main() {
    for ( int i = 0; i < 100; i++ ) {
        for ( int j = 0; j < 100; j++ ) {
            cnt[i][j] = 0;
        }
    }
    R = VS( 9 );
    for ( int i = 0; i < 9; i++ ) {
        cin >> R[i];
    }
    dfs( 0, 0, 0, 0 );
    cout << endl;
    return 0;
}

C++: #include <cstdio>

using namespace std;

#define rep(i,n) for(int i=0; i<int(n); ++i)

int main()
{
	int field[5][5] = {{0}};
	rep(i, 9){
		char str[6];
		scanf("%s", str);
		if(i%2){
			rep(j, 5){
				int a = str[j]-'0';
				field[i/2][j] |= a<<2;
				field[i/2+1][j] |= a;
			}
		}else{
			rep(j, 4){
				int a = str[j]-'0';
				field[i/2][j] |= a<<1;
				field[i/2][j+1] |= a<<3;
			}
		}
	}

	putchar('R');
	int y=0, x=1;
	int pre = 1;
	bool right = false;
	do{
		// printf("(%d, %d)\n", x, y);
		pre = (pre+2)%4;
		int dire = pre;
		do{
			dire = (dire + right*2+1)%4;
		}while(!((field[y][x]>>dire)&1));
		if(dire == pre)
			right = !right;
		pre = dire;
		putchar("URDL"[dire]);

		int dx[] = {0, 1, 0, -1};
		int dy[] = {-1, 0, 1, 0};
		x += dx[dire];
		y += dy[dire];
	}while((y!=0 || x!=0) && !right);
	puts("");

	return 0;
}