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 <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

#define East  1
#define South 2
#define West  4
#define North 8

int main()
{
//	cut here before submit 
//	freopen("testcase.pg", "r", stdin);
	string str = "";
	vector <string> grid;
	int maxlen = 0;

	while (getline (cin, str ) ){
		if (str.empty() ){
			break;
		} // end if
		int len = str.length();
		maxlen = max (maxlen, len );
		grid.push_back(str );
	} // end while

	int size = grid.size();
	vector <vector <char> > room((size+1)/2+1, vector <char> (maxlen, 0 ) );
	int i,j,k;

	for (i = 0; i < size; ++i){
		for (j = 0; j < grid[i].length(); ++j){
			if (grid[i][j] == '1'){
				if (i % 2 == 0){	// north or south wall
					room[i/2][j] |= South;
				}else{			// east or west wall
					room[i/2+1][j-1] |= East;
				} // end if
			} // end if
		} // end for
	} // end for

	for (i = 0; i < room.size(); ++i){
		for (j = 0; j < room[i].size(); ++j){
			if (i == 0){
				room[i][j] |= North;
			}else if (i == room.size() - 1){
				room[i][j] |= South;
			} // end if
			if (i > 0 && room[i-1][j] & South){
				room[i][j] |= North;
			} // end if
			if (j == 0){
				room[i][j] |= West;
			}else if (j == room[i].size() - 1){
				room[i][j] |= East;
			} // end if
			if (j > 0 && room[i][j-1] & East){
				room[i][j] |= West;
			} // end if
		} // end for
	} // end for

	int row = 0;
	int col = 0;
	int dir = East;
	int right_hand = ( (dir << 1) > 8 ? 1 : (dir << 1) );
	string res = "";
	res += 'R';
	bool turn = false;
	int reach = 0;

	do{
		if (turn || (right_hand & room[row][col]) ){
			turn = false;
			// go faword
			switch (dir){
				case East:
					if (!(room[row][col] & East)){ 
						++col;// res += 'R';
						if (right_hand & room[row][col]){
							res += 'R';
						} // end if
					}else{
						dir = North;
						if (right_hand & room[row][col]){
							res += 'U';
						} // end if
						turn = true;
					} // end if
					break;
				case South:
					if (!(room[row][col] & South)){
					 	++row;// res += 'D';
						if (right_hand & room[row][col]){
							res += 'D';
						} // end if
					}else{
						dir = East;
						if (right_hand & room[row][col]){
							res += 'R';
						} // end if
						turn = true;
					} // end if
					break;
				case West:
					if (!(room[row][col] & West)){
						--col;// res += 'L';
						if (right_hand & room[row][col]){
							res += 'L';
						} // end if
					}else{
						dir = South;
						if (right_hand & room[row][col]){
							res += 'D';
						} // end if
						turn = true;
					} // end if
					break;
				case North:
					if (!(room[row][col] & North)){
						--row;// res += 'U';
						if (right_hand & room[row][col]){
							res += 'U';
						} // end if
					}else{
						dir = West;
						if (right_hand & room[row][col]){
							res += 'L';
						} // end if
						turn = true;
					} // end if  
					break;
			} // end switch
		}else{ // if !(right_hand & room[row][col])
			// turn
			switch (dir){
				case East:  dir = South; break;
				case South: dir = West; break;
				case West:  dir = North; break;
				case North: dir = East; break;
			} // end switch
			turn = true;
		} // end if

		right_hand = ( (dir << 1) > 8 ? 1 : (dir << 1) );

		if (row == 1 && col == 0){
			++reach;
		} // end if

	} while (reach < 3);
	room.clear();

	cout << res << endl;
	
	return 0;
}

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

int main(){
    char ma[11][11];
    memset(ma,'0',sizeof(ma));
    for(int i=1;i<10;i++){
        if(i%2==1)
            for(int j=2;j<9;j+=2)
                cin>>ma[i][j];
        else
            for(int j=1;j<10;j+=2)
                cin>>ma[i][j];
    }
    int x=1,y=1,dir=0;
    int mv[4][2]={{2,0},{0,2},{-2,0},{0,-2}};
    int ts[4][8]={{1,-1,1,0,0,-1,0,1},{1,1,0,1,1,0,-1,0},{-1,1,-1,0,0,1,0,-1},{-1,-1,0,-1,-1,0,1,0}};
    string str[4]={"R","D","L","U"};
    string path="";
    int ch=0;
    for(int k=0;k<40;k++){
        int wen=1;
        while(ma[y+ts[dir][3]][x+ts[dir][2]]=='1'){
            y+=mv[dir][1];
            x+=mv[dir][0];
            wen=0;
            path+=str[dir];
            wen++;
        }
        if(x==1&&y==1)
            break;
        
        if(ma[y+ts[dir][5+2*ch]][x+ts[dir][4+2*ch]]=='1')ch=(ch+1)%2;
        do{
            if(ch==0)dir=(dir+1)%4;
            else dir=(dir+4-1)%4;
        }while((y+ts[dir][3]>10||y+ts[dir][3]<0||x+ts[dir][2]>10||x+ts[dir][2]<0)||ma[y+ts[dir][1]][x+ts[dir][0]]=='1');
        
    }
    cout<<path<<endl;
}
//RRRRDDDDLLLUUURRDDLURULLDDDRRRUUUULLLL
//RRRRDDDDLLLUUURRDDLURULLDDDRRRUUUULLLL

C++: #include <iostream>
#include <algorithm>

using namespace std;

const char mark[4] = {'R', 'D', 'L', 'U'};
const int dir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

int main(void) {
    bool w[5][9];
    for (int i = 0; i < 9; i++) {
        int x = 4 + i % 2;
        for (int j = 0; j < x; j++) {
            char c;
            cin >> c;
            w[j][i] = (c == '1');
        }
    }
    int x = 0, y = 0, d = 0;
    do {
        int dx, dy, _x, _y;
        d--;
        if (d < 0) d += 4;
        for (int i = 0; i < 4; i++) {
            dx = dir[d][0];
            dy = dir[d][1];
            _x = x + dx;
            _y = y + dy;
            if (_x >= 0 && _x <= 4 && _y >= 0 && _y <= 4) {
                if (d % 2 == 0 && w[min(x, _x)][y * 2]) break;
                if (d % 2 == 1 && w[x][min(y, _y) * 2 + 1]) break;
            }
            d++;
            d %= 4;
        }
        x = _x;
        y = _y;
        cout << mark[d];
    } while (!(x == 0 && y == 0));

    cout << endl;

    return 0;
}