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>
#include <vector>
#include <algorithm>

using namespace std;


int main(){

	while(1){
	char yoko[10][10];
	char tate[10][10];
	
	for(int i = 0; i < 5; i++){
		for(int j = 0; j < 4; j++){
			cin>>yoko[i][j];
		}
		if(i!=4){
			for(int j = 0; j < 5; j++){
				cin>>tate[i][j];
			}
		}
	}
	if(cin.eof())
		break;


	// 0,1,2,3ÅEAºA¶Aã
	int angle=0;
	int px,py;
	px=py=0;
	while(1){
		if(angle==0){
			if(px!=4&&yoko[py][px]=='1'){
				cout<<"R";
				px++;
			}
			else{
				// ãÖ
				if(py!=0&&tate[py-1][px]=='1'){
					py--;
					angle=3;
					cout<<"U";
				}
				// ºÉÇª êÎAºÖ
				else if(py!=4&&tate[py][px]=='1'){
					py++;
					angle=1;
					cout<<"D";
				}
				else{
					px--;
					angle=2;
					cout<<"L";
				}
			}
		}
		// º
		else if(angle==1){
			if(py!=4&&tate[py][px]=='1'){
				cout<<"D";
				py++;
			}
			else{
				// ºÉÇª³¯êÎA½]
				if(px!=4&&yoko[py][px]=='1'){
					cout<<"R";
					angle=0;
					px++;
				}
				else if(px!=0&&yoko[py][px-1]=='1'){
					cout<<"L";
					angle=2;
					px--;
				}
				else{
					py--;
					angle=3;
					cout<<"U";
				}
			}
		}
		// ¶
		else if(angle==2){
			if(px!=0&&yoko[py][px-1]=='1'){
				cout<<"L";
				px--;
			}
			else{
				// ºÉÇª êÎAºÖ
				if(py!=4&&tate[py][px]=='1'){
					py++;
					angle=1;
					cout<<"D";
				}
				// ãÖ
				else if(py!=0&&tate[py-1][px]=='1'){
					py--;
					angle=3;
					cout<<"U";
				}
				else{
					px++;
					angle=0;
					cout<<"R";
				}
			}
		}
		// ã
		else if(angle==3){
			if(py!=0&&tate[py-1][px]=='1'){
				cout<<"U";
				py--;
			}
			else{
				// ºÉÇª³¯êÎA½]
				if(px!=0&&yoko[py][px-1]=='1'){
					cout<<"L";
					angle=2;
					px--;
				}
				else if(px!=4&&yoko[py][px]=='1'){
					cout<<"R";
					angle=0;
					px++;
				}
				else{
					py++;
					angle=1;
					cout<<"D";
				}
			}
		}
		if(px==0&&py==0)
			break;
		}
		cout<<endl;

		}
		return 0;
}

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 == L ) break;
        if ( r == 3 && c == 2 && s == U ) 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;
}