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>
#include <cstring>
#include <string>

using namespace std;


int main(){

	int yoko[10][10];
	int tate[10][10];
	for(int i = 0; i < 5; i++){
		for(int j = 0; j < 4; j++){
				char c;
				cin>>c;
				yoko[i][j]=c-'0';
		}
		if(i!=4){
			for(int j = 0; j < 5; j++){
				char c;
				cin>>c;
				tate[i][j]=c-'0';
			}
		}
	}
	cout<<'R';
	int cx=1;
	int cy=0;

	// 0:E,1:º,2:¶,3:ã
	int angle=0;
	while(1){
		int nx=cx;
		int ny=cy;
		if(angle==0){

			nx=cx+1;
			ny=cy;
			if(cy!=0&&tate[cy-1][cx]){
				angle=3;
				cy--;
				cout<<"U";
			}
			// Çª éÈç
			else if(nx>=0&&ny>=0&&ny<5&&nx<5&&yoko[cy][cx]){
				cy=ny;
				cx=nx;
				cout<<'R';
			}
			// È¢ÈçAü«ðÏX
			else if(tate[cy][cx]){
				angle=1;
				cout<<"D";
				cy++;
			}
			else{
				angle=2;
				cout<<"L";
				cx--;
			}
		}
		else if(angle==1){
			nx=cx;
			ny=cy+1;
			// EÌÇðDæ
			if(cx!=4&&yoko[cy][cx]){
				cx++;
				cout<<"R";
				angle=0;
			}
			// Çª éÈç
			else if(nx>=0&&ny>=0&&ny<5&&nx<5&&tate[cy][cx]){
				cy=ny;
				cx=nx;
				cout<<'D';
			}
			// È¢ÈçAü«ðÏX
				// ¶
			else if(cx!=0&&yoko[cy][cx-1]){
				cx--;
				cout<<"L";
				angle=2;
			}
			// ÍñÄñ
			else{
				cy--;
				cout<<'U';
				angle=3;
			}
		}
		// ¶
		else if(angle==2){
			nx=cx-1;
			ny=cy;
			// ºÌÇªDæ
			if(cy!=4&&tate[cy][cx]){
				cout<<'D';
				cy++;
				angle=1;
			}
			// Çª éÈç
			else if(nx>=0&&ny>=0&&ny<5&&nx<5&&yoko[cy][cx-1]){
				cy=ny;
				cx=nx;
				cout<<'L';
			}
			// È¢ÈçAü«ðÏX
			// ã
			else if(cy!=0&&tate[cy-1][cx]){
				cout<<'U';
				angle=3;
				cy--;
			}
			// ÍñÄñ
			else{
				cout<<'R';
				angle=0;
				cx++;
			}
		}
		// ã
		else if(angle==3){
			nx=cx;
			ny=cy-1;
			// Çª éÈç
			// ¶ÌÇðDæ
			if(cx!=0&&yoko[cy][cx-1]){
				cout<<'L';
				angle=2;
				cx--;
			}
			else if(nx>=0&&ny>=0&&ny<5&&nx<5&&tate[cy-1][cx]){
				cy=ny;
				cx=nx;
				cout<<'U';
			}
			// È¢ÈçAü«ðÏX
			// E
			else if(cx!=4&&yoko[cy][cx]){
				angle=0;
				cout<<'R';
				cx++;
			}
			// ÍñÄñ
			else{
				cout<<'D';
				cy++;
				angle=1;
			}
	   }
		if(cx==0&&cy==0)
			break;
	}
	cout<<endl;
	
	return 0;
}

C++: #include <stdio.h>
#include <stdbool.h>

char s[13][7];
int order[24] = {0, 1, 2, 0, 3, 2, 2, 1, 0, 2, 3, 0,
                 3, 0, 1, 3, 2, 1, 1, 0, 3, 1, 2, 3};
int nds[24] = {4, 0, 7, 6, 1, 5, 5, 2, 6, 7, 3, 4,
               3, 4, 0, 1, 5, 2, 2, 6, 1, 0, 7, 3};
int ds[8] = {1, 3, 1, 3, 0, 2, 0, 2};
int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
char ls[8] = {'R', 'L', 'R', 'L', 'U', 'D', 'U', 'D'};
int i, j;

bool doesWallExist(int x, int y, int d){
    // printf("%d, %d, %d, %d, %d: ", x, y, d, x+(dx[d]-1)/2, 2*y+(dy[d]-1)/2);
    if(s[2*y+dy[d]][x+(dx[d]-1)/2] == '1'){
        //puts("o");
        return true;
    }
    //puts("x");
    return false;
}

int main(){
    for(i=0;i<13;i++){
        for(j=0;j<7;j++){
            s[i][j] = '0';
        }
    }

    for(i=2;i<=10;i++){
        int ub = i%2?5:4;
        for(j=0;j<ub;j++){
            scanf("%c", &s[i][j+1]);
        }
        scanf("%*c");
    }

    bool f = false;
    int x = 1, y = 1, d = 0;
    while(!(x == 1 && y == 1 && f)){
        if(!f){f = true;}

        // printf("%d, %d, %d\n", x, y, d);
        putchar(ls[d]);
        x += dx[ds[d]]; y += dy[ds[d]];

        for(i=0;i<3;i++){
            if(doesWallExist(x, y, order[d*3+i])){
                d = nds[d*3+i];
                break;
            }
        }
    }
    puts("");

    /* for(int i=0;i<13;i++){ */
    /*     for(int j=0;j<7;j++){ */
    /*         putchar(s[i][j]); */
    /*     } */
    /*     puts(""); */
    /* } */

    return 0;
}

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];
}

bool isBackwardWall(int x,int y,int dir){
	if(dir==W)	y--;
	if(dir==S)	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;
}

void goBackward(int &x,int &y,int &dir){
	if(dir==E)	x--;
	if(dir==N)	y++;
	if(dir==W)	x++;
	if(dir==S)	y--;
	dir=(dir+2)%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)){
				if(!isBackwardWall(x,y,dir))
						goBackward(x,y,dir);
				else	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;
}