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 <string>

using namespace std;

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const string dir = "RDLU";

int main()
{
    string input;

    while (cin >> input) {
        bool map[5][5][4];

        // Initialization
        for (int i = 0; i < 5; i++)
            for (int j = 0; j < 5; j++)
                for (int k = 0; k < 4; k++)
                    map[i][j][k] = false;

        // Input (0,0) - (0,4)
        for (int i = 0; i < 4; i++) 
            if (input[i] == '1') {
                map[0][i][0] = true;
                map[0][i + 1][2] = true;
            }

        // Input Others
        for (int i = 0; i < 8; i++) {
            cin >> input;
            int lim;
            (i % 2) ? (lim = 4) : (lim = 5);

            for (int j = 0; j < lim; j++)
                if (input[j] == '1') {
                    if (i % 2) {
                        map[(i + 1) / 2][j][0] = true;
                        if (j)
                            map[(i + 1) / 2][j + 1][2] = true;
                    }
                    else {
                        map[i / 2][j][1] = true;
                        map[(i / 2) + 1][j][3] = true;
                    }
                }
        }

        // algorithm
        int x, y, d;

        x = y = d = 0;
        do {
            //cout << "(" << y << "," << x << "," << d << ")" << endl;
            if (map[y][x][d])
                ;
            else if (map[y][x][(d + 1) % 4]) 
                d = (d + 1) % 4;
            else if (map[y][x][(d + 3) % 4]) 
                d = (d + 3) % 4;

            map[y][x][d] = false;
            x += dx[d];
            y += dy[d];
            cout << dir[d];
        } while (x || y);
    }

    

    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][6]={{1,-1,1,0,0,-1},{1,1,0,1,1,0},{-1,1,-1,0,0,1},{-1,-1,0,-1,-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]][x+ts[dir][4]]=='1')ch=1;
        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<string>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
using namespace std;

int main() {

    vector<vector<char> > root (9, vector<char>(5));

    char c;
    for(int i = 0; i < 9; i++) {
        for(int j = 0; j < 4 + (i % 2); j++) {
            cin >> c;
            root[i][j] = c;
        }
    }

    cout << "R";

    int x = 1;
    int y = 0;
    int d = 2;
    char dirs [] = { 'L', 'U', 'R', 'D', 'L', 'U', 'R' }; 

    while ( x || y ) {
        bool gone = false;
        for (int i = -1; i < 2; i++) {
            switch(dirs[d + i]) {
                case 'L':
                    if (x > 0 && root[2 * y][x - 1] == '1') {
                        x -= 1;
                        d = 4;
                        cout << 'L';
                        gone = true;
                    }
                    break;
                case 'U':
                    if (y > 0 && root[2 * y - 1][x] == '1') {
                        y -= 1;
                        d = 1;
                        cout << 'U';
                        gone = true;
                    }
                    break;
                case 'R':
                    if (x < 4 && root[2 * y][x] == '1') {
                        x += 1;
                        d = 2;
                        cout << 'R';
                        gone = true;
                    }
                    break;
                case 'D':
                    if (y < 4 && root[2 * y + 1][x] == '1') {
                        y += 1;
                        d = 3;
                        cout << 'D';
                        gone = true;
                    }
                    break;
            }
            if (gone) break;
        }
    }
    cout << endl;
     
    return 0;
}