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 <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

void input(bool grid[][9])
{
	rep(i,9){
		string s;
		cin>>s;
		if(i%2==0)
			rep(j,4)
				grid[i][j*2+1]=s[j]-'0';
		else
			rep(j,5)
				grid[i][j*2]=s[j]-'0';
	}
}

enum dir{
	UP,RIGHT,DOWN,LEFT
};
const int di[]={-1,0,1,0};
const int dj[]={0,1,0,-1};
const char output[]="URDL";

bool in_range(int i,int j)
{
	return 0<=i && i<9 && 0<=j && j<9;
}

int main()
{
	bool grid[9][9]={{0}};
	input(grid);
	//rep(i,9){
	//	rep(j,9)
	//		cout<<grid[i][j]<<" ";
	//	cout<<endl;
	//}
	
	int i=0,j=0;
	dir prev=RIGHT;
	for(;;){
		//printf("# (%d,%d) prev:%c\n",i,j,output[prev]);
		
		dir next[4];
		if(prev==UP){
			next[0]=LEFT;next[1]=UP;next[2]=RIGHT;next[3]=DOWN;
		}
		else if(prev==RIGHT){
			next[0]=UP;next[1]=RIGHT;next[2]=DOWN;next[3]=LEFT;
		}
		else if(prev==DOWN){
			next[0]=RIGHT;next[1]=DOWN;next[2]=LEFT;next[3]=UP;
		}
		else if(prev==LEFT){
			next[0]=DOWN;next[1]=LEFT;next[2]=UP;next[3]=RIGHT;
		}
		int k;
		for(k=0;k<3;k++){
			if(in_range(i+di[next[k]],j+dj[next[k]]) && grid[i+di[next[k]]][j+dj[next[k]]])
				break;
		}
		
		//printf("%d(%c)\n",k,output[next[k]]);
		cout<<output[next[k]];
		
		i+=di[next[k]]*2;
		j+=dj[next[k]]*2;
		prev=next[k];
		
		if(i==0 && j==0)
			break;
	}
	cout<<endl;
	
	return 0;
}

C++: #include <string>
#include <iostream>
using namespace std;
int dir[] = { 0, 1, 0, -1 };
string e = "RDLU";
string s[9]; bool d[6][6][4];
int main() {
	for (int i = 0; i < 9; i++) cin >> s[i];
	for (int i = 0; i < 5; i++) {
		for (int j = 0; j < 4; j++) {
			if (s[i * 2][j] == '1') d[i][j + 1][1] = d[i + 1][j + 1][3] = true;
		}
	}
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 5; j++) {
			if (s[i * 2 + 1][j] == '1') d[i + 1][j][0] = d[i + 1][j + 1][2] = true;
		}
	}
	string ret = "R";
	int x = 0, y = 1, dr = 0;
	while (true) {
		if (d[x][y][dr]) dr = (dr + 3) & 3, ret += e[dr];
		else {
			x += dir[dr], y += dir[dr ^ 1];
			if (x == 1 && y == 0) break;
			if (!d[x][y][(dr + 1) & 3]) {
				dr = (dr + 1) & 3;
				x += dir[dr], y += dir[dr ^ 1]; ret += e[dr];
				if (x == 1 && y == 0) break;
			}
			else ret += e[dr];
		}
	}
	cout << ret << endl;
	return 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<int(n);i++)

void input(bool grid[][9])
{
	rep(i,9){
		string s;
		cin>>s;
		if(i%2==0)
			rep(j,4)
				grid[i][j*2+1]=s[j]-'0';
		else
			rep(j,5)
				grid[i][j*2]=s[j]-'0';
	}
}

enum dir{
	UP,RIGHT,DOWN,LEFT
};
const int di[]={-1,0,1,0};
const int dj[]={0,1,0,-1};
const char output[]="URDL";

bool in_range(int i,int j)
{
	return 0<=i && i<9 && 0<=j && j<9;
}

int main()
{
	bool grid[9][9]={{0}};
	input(grid);
	
	int i=0,j=0;
	dir prev=RIGHT;
	for(;;){
		dir next[4]={LEFT,UP,RIGHT,DOWN};
		rotate(next,next+prev,next+4);
		
		int k;
		for(k=0;k<3;k++){
			if(in_range(i+di[next[k]],j+dj[next[k]]) && grid[i+di[next[k]]][j+dj[next[k]]])
				break;
		}
		
		cout<<output[next[k]];
		
		i+=di[next[k]]*2;
		j+=dj[next[k]]*2;
		prev=next[k];
		
		if(i==0 && j==0)
			break;
	}
	cout<<endl;
	
	return 0;
}

C++: #include <iostream>
#include <string>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <algorithm>

using namespace std;

char x[11][11];

void search(int i, int j, int direction);

int main () {
    
    for(int i=0; i<11; i++){
        for(int j=0; j<11; j++){
            x[i][j]='0';
        }
    }


    while(cin
          >>x[1][2]>>x[1][4]>>x[1][6]>>x[1][8]
          >>x[2][1]>>x[2][3]>>x[2][5]>>x[2][7]>>x[2][9]
          >>x[3][2]>>x[3][4]>>x[3][6]>>x[3][8]
          >>x[4][1]>>x[4][3]>>x[4][5]>>x[4][7]>>x[4][9]
          >>x[5][2]>>x[5][4]>>x[5][6]>>x[5][8]
          >>x[6][1]>>x[6][3]>>x[6][5]>>x[6][7]>>x[6][9]
          >>x[7][2]>>x[7][4]>>x[7][6]>>x[7][8]
          >>x[8][1]>>x[8][3]>>x[8][5]>>x[8][7]>>x[8][9]
          >>x[9][2]>>x[9][4]>>x[9][6]>>x[9][8]
          )
        
        
    {
        search(1, 1, 1);
        
    }
    
    return 0;
}

void search(int i, int j, int direction){
    while(1){
    char around[4];
    around[0]=x[i-1][j];
    around[1]=x[i][j+1];
    around[2]=x[i+1][j];
    around[3]=x[i][j-1];
    
    char output[4]={'U','R','D','L'};
    int next[4]={0,1,2,3};
    
        int move[4][2]={0};
    if(around[0]=='1'){
        move[0][0]=i-2;move[0][1]=j;
    }
    if(around[1]=='1'){
        move[1][0]=i;move[1][1]=j+2;
    }
    if(around[2]=='1'){
        move[2][0]=i+2;move[2][1]=j;
    }
    if(around[3]=='1'){
        move[3][0]=i;move[3][1]=j-2;
    }
    
    for(int k=0; k<3; k++){
        int temp = (direction+3+k)%4;
        if(around[temp]=='1'){
            direction=next[temp];
            i=move[temp][0];
            j=move[temp][1];
            cout<<output[temp]<<endl;
            break;
        }
    }
        if(i==1&&j==1){
            break;
        }
    }
    
}