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;

string line[9];

bool check( int x, int y ) {
    if ( y < 0 || y >= 9 ) return false;
    if ( y % 2 == 0 ) {
        if ( x < 0 || x >= 4 ) return false;
    } else {
        if ( x < 0 || x >= 5 ) return false;
    }
    return true;
}

void solve( int a, int x, int y ) {
    if ( y % 2 == 0 ) {
        cout << ( a ? "R" : "L" );
    } else {
        cout << ( a ? "U" : "D" );
    }

    if ( y % 2 == 0 ) {
        if ( a ) {
            if ( check(x+1,y-1) && line[y-1][x+1] == '1' ) {
                solve( 1, x+1, y-1 );
            } else if ( check(x+1,y) && line[y][x+1] == '1' ) {
                solve( 1, x+1, y );
            } else if ( check(x+1,y+1) && line[y+1][x+1] == '1' ) {
                solve( 0, x+1, y+1 );
            }
        } else {
            if ( check(x,y-1) && line[y-1][x] == '1' ) {
                solve( 1, x, y-1 );
            } else if ( check(x-1,y) && line[y][x-1] == '1' ) {
                solve( 0, x-1, y );
            } else if ( check(x,y+1) && line[y+1][x] == '1' ) {
                solve( 0, x, y+1 );
            }
        }
    } else {
        if ( a ) {
            if ( check(x-1, y-1) && line[y-1][x-1] == '1' ) {
                solve( 0, x-1, y-1 );
            } else if ( check(x, y-2) && line[y-2][x] == '1' ) {
                solve( 1, x, y-2 );
            } else if ( check(x, y-1) && line[y-1][x] == '1' ) {
                solve( 0, x, y-1 );
            }
        } else {
            if ( check(x, y+1) && line[y+1][x] == '1' ) {
                solve( 1, x, y+1 );
            } else if ( check(x, y+2) && line[y+2][x] == '1' ) {
                solve( 0, x, y+2 );
            } else if ( check(x-1, y+1) && line[y+1][x-1] == '1' ) {
                solve( 0, x-1, y+1 );
            }
        }
    }
}

int main() {
    for ( int i = 0; i < 9; i++ ) {
        cin >> line[i];
    }

    solve( 1, 0, 0 );
    cout << endl;

    return 0;
}

C++: #define _USE_MATH_DEFINES
 
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

char tate[4][5];
char yoko[5][4];
bool flag = false;

void test(int x, int y, int j){
	//cout<<endl;
	//cout<<x<<" "<<y<<" "<<endl;
	int i;
	//cin>>i;
	if(x==0&&y==0){
		//cout<<endl;
		return;
	}

	if(j==0){                                  //右に動いた時
		if(x-1>=0 && tate[x-1][y]=='1'){       //行き止まり　上に
			cout<<"U";
			test(x-1, y, 1);
		}
		else if(y+1<5 && yoko[x][y]=='1'){     //右に行ける
			cout<<"R";
			test(x, y+1, 0);                   
		}
		else if(/*x+1<5 && *//*y+1<5 &&*/ tate[x][y]=='1'){     //行き止まり　下に
			cout<<"D";
			test(x+1, y, 3);    //下に
		}
	}
	else if(j==1){                             //上に動いた時
		if(y-1>=0 && yoko[x][y-1]=='1'){       //行き止まり　左に
			cout <<"L";
			test(x, y-1, 2);
		}
		else if(x-1>=0 && tate[x-1][y]=='1'){  //上に行ける
			cout <<"U";
			test(x-1, y, 1);
		}
		else if(y+1<5 && yoko[x][y]=='1'){     //行き止まり　右に
			cout <<"R";
			test(x, y+1, 0);
		}
	}
	else if(j==2){                             //左に動いた時
		if(/*x+1<5 &&*/ tate[x][y]=='1'){          //行き止まり　下に
			cout<<"D";
			test(x+1, y, 3);
		}
		else if(y-1>=0 && yoko[x][y-1]=='1'){  //左に行けるなら
			cout<<"L";
			test(x, y-1, 2);
		}
		else if(x-1>=0 && tate[x-1][y]=='1'){  //行き止まり　上に
			cout<<"U";
			test(x-1, y, 1);
		}
	}
	else if(j==3){                             //下に動いた時
		if(y+1<5 && yoko[x][y]=='1'){          //行き止まり　右に
			cout <<"R";
			test(x, y+1, 0);
		}
		else if(/*x+1<5 &&*/ tate[x][y]=='1'){     //下に行けるなら
			cout <<"D";
			test(x+1, y, 3);
		}
		else if(y-1>=0 && yoko[x][y-1]=='1'){  //行き止まり　左に
			cout <<"L";
			test(x, y-1, 2);
		}
	}
}

int main(){

	for(int i=0;i<4;i++){
		cin >> yoko[i][0] >> yoko[i][1] >> yoko[i][2] >> yoko[i][3];
		cin >> tate[i][0] >> tate[i][1] >> tate[i][2] >> tate[i][3] >> tate[i][4];
	}
	cin >> yoko[4][0] >> yoko[4][1] >> yoko[4][2] >> yoko[4][3];
	
	cout << "R";
	test(0, 1, 0);
	cout << endl;

	return 0;
}

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

bool h[100][100]; // setinel
bool v[100][100];


int main(){
	string str, ans = "";
	char dir = 'n';
	int mx = 1;
	int my = 1;

	int i = 1;
	int j = 1;
	int len;

	while(cin >> str){
		if(i == 1) len = str.size();
		if(str.size() == len){
			for (int k = 0; k < str.size(); k++) {
				h[i][k+1] = str[k] == '1' ? true : false;
			}
			i++;
		}else{
			for (int k = 0; k < str.size(); k++) {
				v[j][k+1] = str[k] == '1' ? true : false;
			}
			j++;
		}
	}
	
	do{
		if (v[my-1][mx] && dir != 'D' && (dir=='R' || !h[my][mx-1])) {
			dir = 'U';
			my--;
		}else if (h[my][mx] && dir != 'L' && (dir=='D' || !v[my-1][mx])) {
			dir = 'R';
			mx++;
		}else if (v[my][mx] && dir != 'U' && (dir=='L' || !h[my][mx])) {
			dir = 'D';
			my++;
		}else if (h[my][mx-1] && dir != 'R' && (dir=='U' || !v[my][mx])) {
			dir = 'L';
			mx--;
		}
		ans += dir;
	}while(!(mx == 1 && my == 1));

	cout << ans << endl;

	return 0;
}