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;

#define U 0
#define D 1
#define L 2
#define R 3

class point
{
public:
	int x,y,d;
	point()
	{
		x=y=0;
		d=R;
	}
	void move()
	{
		if(d==R)
		{
			x++;
		}
		else if(d==L)
		{
			x--;
		}
		else if(d==U)
		{
			y--;
		}
		else
		{
			y++;
		}
	}
	char dir()
	{
		if(d==U)
		{
			return 'U';
		}
		else if(d==D)
		{
			return 'D';
		}
		else if(d==L)
		{
			return 'L';
		}
		else
		{
			return 'R';
		}
	}
};

class map
{
public:
	string s[9];
	void input()
	{
		for(int i=0;i<9;i++)
		{
			cin>>s[i];
		}
	}
	int state(int x, int y, int d)
	{
		if(d==U)
		{
			y=2*y-1;
		}
		else if(d==D)
		{
			y=2*y+1;
		}
		else if(d==L)
		{
			x=x-1;
			y=y*2;
		}
		else
		{
			y=y*2;
		}
		if(y<0||y>=9||x<0||x>=s[y].length())
		{
			return 0;
		}
		else{
			return s[y].at(x)-'0';
		}
	}
};

int main(void)
{
	point p;
	map m;
	m.input();
	int dir[4][4]=
	{
		{L,U,R,D},
		{R,D,L,U},
		{D,L,U,R},
		{U,R,D,L}
	};
	while(!(p.d==L&&p.x==0&&p.y==0))
	{
		for(int i=0;i<4;i++)
		{
			if(p.d==i)
			{
				for(int j=0;j<4;j++)
				{
					if(m.state(p.x,p.y,dir[i][j])==1)
					{
						p.d=dir[i][j];
						break;
					}
				}
				break;
			}
		}
		p.move();
		cout<<p.dir();
	}
	cout<<endl;
}

C++: #include<string> 
#include<vector>
#include<iostream>
using namespace std;
string vec="RULD";
bool map[20][20][4];
vector< string > maphor,mapver;
int xsize,ysize;
void init(){
	for(int i=0;i<xsize;i++){
		for(int j=0;j<ysize;j++){
			for(int k=0;k<4;k++){
				map[i][j][k]=0;
			}
		}
	}
}
void setmap(){
	for(int i=0;i<xsize;i++){
		for(int j=0;j<ysize;j++){
			if(-1<i&&i<ysize&&-1<j&&j<xsize){
				if(maphor[i][j]=='1'){
					map[i][j][0]=1;
				}
			}
			if(-1<i&&i<ysize&&-1<j-1&&j-1<xsize){
				if(maphor[i][j-1]=='1'){
					map[i][j][2]=1;
				}
			}
			if(-1<i&&i<ysize-1&&-1<j&&j<xsize){
				if(mapver[i][j]=='1'){
					map[i][j][3]=1;
				}
			}
			if(-1<i-1&&i-1<ysize-1&&-1<j&&j<xsize){
				if(mapver[i-1][j]=='1'){
					map[i][j][1]=1;
				}
			}
		}
	}
}

void solve(){
	int x=0,y=0;
	int v=0;
	int loop[4]={1,0,3,2};
	int vx[4]={1,0,-1,0};
	int vy[4]={0,-1,0,1};
	while(1){
		//cout<<x<<" "<<y<<endl;
		for(int i=0;i<4;i++){
			//cout<<vec[(v+loop[i])%4];
			if(x==0&&y==0&&(v+loop[i])%4==2){
				return;
			}
			if(map[y][x][(v+loop[i])%4]==1){
				v+=loop[i];
				v=v%4;
				x+=vx[v];
				y+=vy[v];
				//cout<<endl;
				cout<<vec[v];
				break;
			}
		}
	}
}

int main(){
	string tmp;
	for(int i=0;cin.eof()!=true;i++){
		cin>>tmp;
		if(i%2==0){
			maphor.push_back(tmp);
		}else{
			mapver.push_back(tmp);
		}
	}
	xsize=maphor[0].size()+1;
	ysize=mapver.size()+1;
	init();setmap();
	
	/*
	for(int i=0;i<xsize;i++){
		for(int j=0;j<ysize;j++){
			for(int k=0;k<4;k++){
				cout<<map[i][j][k];
			}
			cout<<" ";
		}
		cout<<endl;
	}*/
	solve();
	cout<<endl;
	
	return 0;
	
}

C++: #include <iostream>
#include <string>
#include <array>
#include <bitset>
#include <cstdint>

int main()
{
	enum { Left, Up, Right, Down };

	typedef std::array<std::bitset<4>, 5> Row;
	typedef std::array<Row, 5> Matrix;
	Matrix matrix;
	for (auto& row : matrix) {
		row.fill(std::bitset<4>());
	}

	std::string input;
	std::getline(std::cin, input);
	for (std::uint16_t x = 0; x < 4U; ++x) {
		if (input[x] == '1') {
			matrix[0][x].set(Right);
			matrix[0][x + 1].set(Left);
		}
	}

	for (std::uint16_t y = 0; y < 4U; ++y) {
		std::getline(std::cin, input);
		for (std::uint16_t x = 0; x < 5U; ++x) {
			if (input[x] == '1') {
				matrix[y][x].set(Down);
				matrix[y + 1][x].set(Up);
			}
		}
		std::getline(std::cin, input);
		for (std::uint16_t x = 0; x < 4U; ++x) {
			if (input[x] == '1') {
				matrix[y + 1][x].set(Right);
				matrix[y + 1][x + 1].set(Left);
			}
		}
	}

	std::uint16_t y = 0, x = 0;
	char direct = 'R';
	do {
		if (direct == 'R') {
			if (matrix[y][x][Up]) {
				direct = 'U';
				--y;
			}
			else if (matrix[y][x][Right]) {
				direct = 'R';
				++x;
			}
			else if (matrix[y][x][Down]) {
				direct = 'D';
				++y;
			}
			else {
				direct = 'L';
				--x;
			}
		}
		else if (direct == 'D') {
			if (matrix[y][x][Right]) {
				direct = 'R';
				++x;
			}
			else if (matrix[y][x][Down]) {
				direct = 'D';
				++y;
			}
			else if (matrix[y][x][Left]) {
				direct = 'L';
				--x;
			}
			else {
				direct = 'U';
				--y;
			}
		}
		else if (direct == 'L') {
			if (matrix[y][x][Down]) {
				direct = 'D';
				++y;
			}
			else if (matrix[y][x][Left]) {
				direct = 'L';
				--x;
			}
			else if (matrix[y][x][Up]) {
				direct = 'U';
				--y;
			}
			else {
				direct = 'R';
				++x;
			}
		}
		else if (direct == 'U') {
			if (matrix[y][x][Left]) {
				direct = 'L';
				--x;
			}
			else if (matrix[y][x][Up]) {
				direct = 'U';
				--y;
			}
			else if (matrix[y][x][Right]) {
				direct = 'R';
				++x;
			}
			else {
				direct = 'D';
				++y;
			}
		}
		std::cout << direct << std::flush;
	} while (not (y == 0 and x == 0));
	std::cout << std::endl;

	return 0;
}