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 <bits/stdc++.h>
using namespace std;

double eps = 1e-10;

int main() {
	string s[16], ans("R");
	for(int i = 0; i < 9; ++i){
		cin >> s[i];
	}
	int x = 0, y = 0;
	int d = 0; // 0:right, 1:down, 2:left, 3:up
	bool flag = false;
	while(1){
		if(d == 0){
			if(s[y][x + 1] == '1'){
				ans += 'R';
				x += 1;
			}
			else if(y >= 2 && s[y - 1][x + 1] == '1'){
				ans += 'U';
				y -= 1;
				x += 1;
				d = 3;
			}
			else if(s[y + 1][x + 1] == '1'){
				ans += 'D';
				x += 1;
				y += 1;
				d = 1;
			}
			else{
				ans += 'L';
				d = 2;
			}
		}
		else if(d == 1){
			if(s[y + 2][x] == '1'){
				ans += 'D';
				y += 2;
			}
			else if(s[y + 1][x] == '1'){
				ans += 'R';
				y += 1;
				d = 0;
			}
			else if(s[y + 1][x - 1] == '1'){
				ans += 'L';
				x -= 1;
				y += 1;
				d = 2;
			}
		}
		else if(d == 2){
			if(s[y][x - 1] == '1'){
				ans += 'L';
				x -= 1;
			}
			else if(y >= 2 && s[y - 1][x] == '1'){
				ans += 'U';
				y -= 1;
				d = 3;
			}
			else if(s[y + 1][x] == '1'){
				ans += 'D';
				y += 1;
				d = 1;
			}
		}
		else if(d == 3){
			if(y >= 3 && s[y - 2][x] == '1'){
				ans += 'U';
				y -= 2;
			}
			else if(s[y - 1][x] == '1'){
				y -= 1;
				if(x == 0 && y == 0)
					break;
				ans += 'R';
				d = 0;
			}
			else if(s[y - 1][x - 1] == '1'){
				ans += 'L';
				y -= 1;
				x -= 1;
				d = 2;
			}
		}
		/*if(x == 1 && y == 8 && flag)
			break;
		if(x == 1 && y == 8){
			flag = true;
			//break;
		}*/
		if(x == 0 && y == 0)
			break;
	}
	/*cout << s[8][3] << endl;
	cout << d << endl;*/
	cout << ans << 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';
		}
		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';
		}
		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';
		}
		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';
		}
		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<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==3){
				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 <algorithm>
#include <cstdio>

using namespace std;
#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)
typedef vector<bool> vb;
typedef vector<vb> vvb;

bool in(int x,int y){
    return 0<=x && x<9 && 0<=y && y<9;
}

int main(){
    enum {U,R,D,L};
    const int dy[]={-1,0,1,0};
    const int dx[]={0,1,0,-1};
    vvb g(9,vb(9));
    rep(i,9){
        string s;cin>>s;
        if(i%2==0){
            rep(j,4)g[i][j*2+1]=s[j]-'0';
        }else{
            rep(j,5)g[i][j*2]=s[j]-'0';
        }
    }
    
    int i=0,j=0;
    int prev=R;
    while(1){
        int next[4]={L,U,R,D};
        rotate(next,next+prev,next+4);
        int k=0;
        for(;k<4;k++){
            if(in(i+dy[next[k]],j+dx[next[k]]) && g[i+dy[next[k]]][j+dx[next[k]]]){
                break;
            }
        }
        
        putchar("URDL"[next[k]]);
        i+=dy[next[k]]*2;
        j+=dx[next[k]]*2;
        prev=next[k];
        if(i==0 && j==0){
            break;
        }
    }
    cout<<endl;
}