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<string> 
#include<vector>
#include<iostream>
using namespace std;
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;
	string vec="RULD";
	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 || ((v+loop[i])%4==1)){
				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 <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>

#define X first
#define Y second
#define WIDTH 8
#define HEIGHT 8

using namespace std;

struct point{
	point(int x = 0, int y = 0, char dir = 'R'):x(x), y(y), dir(dir){}
	int x;
	int y;
	char dir;
};

char moveMap(vector<string> &map, point &player){
	switch(player.dir){
	case 'R':
		if(player.y != 0 && map[player.y - 1][player.x + 1] == '1'){
			player.y -= 1;
			player.x += 1;
			player.dir = 'U';
		}
		else if(player.x != map[player.y].size() - 1 && map[player.y][player.x + 1] == '1'){
			player.x += 1;
		}
		else if(player.y != 8 && map[player.y + 1][player.x + 1] == '1'){
			player.y += 1;
			player.x += 1;
			player.dir = 'D';
		}
		else player.dir = 'L';
		break;
	case 'L':
		if(player.y != 8 && map[player.y + 1][player.x] == '1'){
			player.y += 1;
			player.dir = 'D';
		}
		else if(player.x != 0 && map[player.y][player.x - 1] == '1'){
			player.x -= 1;
		}
		else if(player.y != 0 && map[player.y - 1][player.x] == '1'){
			player.y -= 1;
			player.dir = 'U';
		}
		else player.dir = 'R';
		break;
	case 'U':
		if(player.x != 0 && map[player.y - 1][player.x - 1] == '1'){
			player.y -= 1;
			player.x -= 1;
			player.dir = 'L';
		}
		else if(player.y != 1 && map[player.y - 2][player.x] == '1'){
			player.y -= 2;
		}
		else if(player.x != map[player.y].size() - 1 && map[player.y - 1][player.x] == '1'){
			player.y -= 1;
			player.dir = 'R';
		}
		else player.dir = 'D';
		break;
	case 'D':
		if(player.x != map[player.y].size() - 1 && map[player.y + 1][player.x] == '1'){
			player.y += 1;
			player.dir = 'R';
		}
		else if(player.y != 7 && map[player.y + 2][player.x] == '1'){
			player.y += 2;
		}
		else if(player.x != 0 && map[player.y + 1][player.x - 1] == '1'){
			player.y += 1;
			player.x -= 1;
			player.dir = 'L';
		}
		else player.dir = 'U';
		break;
	default:
		break;
	}
	return player.dir;
}

int main(){
	string tmp;
	while(cin >> tmp){
		if(cin.eof()) break;
		
		vector<string> map;
		map.push_back(tmp);
		for(int i = 1; i < 9; i++){
			cin >> tmp;
			map.push_back(tmp);
		}

		point player(0, 0, 'R');
		string root;
		root.push_back('R');
		
		while(1){
			root.push_back(moveMap(map, player));
			if(player.x == 0 && player.y == 0) break;
		}

		for(int i = 0; i < root.size(); i++){
			cout << root[i];
		}
		cout << endl;
	}
	return 0;
}

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

bool mas[11][11][4];
string s = "LURD";
const int dy[] = { 0, -1, 0, 1}, dx[] = { -1, 0, 1, 0};

void dfs( int y, int x, int pos){
  cout << s[pos];
  if(!y && !x){
    cout << endl;
    return;
  }
  for(int i = 0 ; i < 4 ; i++ ){
    int dd = ( pos + 3 + i ) % 4;
    int ny = y + dy[ dd], nx = x + dx[ dd];
    if(mas[y][x][dd]){
      dfs( y + dy[ dd], x + dx[ dd], dd);
      return;
    }
  }
}
int main(){
  char c;
  for(int i = 0 ; i < 9 ; i++ ){
    if(i & 1)
      for(int j = 0 ; j < 5 ; j++ ){
        cin >> c;
        if(c == '1') mas[i / 2][j][3] = mas[i / 2 + 1][j][1] = true;
      }
    else
      for(int j = 0 ; j < 4 ; j++ ){
        cin >> c;
        if(c == '1') mas[i / 2][j][2] = mas[i / 2][j + 1][0] = true;
      }
  }
  dfs( 0, 1, 2);
}

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

using namespace std;

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const char 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 {
            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);
        cout << endl;
    }

    

    return 0;
}