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>
#include<deque>
using namespace std;
#define MAX_MAP 10

deque<string> map;

int y=0,x=-1,vec=0;
string v="RULD";
int dvx[4]={1,0,-1,0};
int dvy[4]={0,-1,0,1};

bool wall_front(){
	switch(vec){
	case 0:
		if(map[y*2+1][(x+2)+1]=='1'){
			return true;
		}else{
			return false;
		}
	case 1:
		if(map[y*2][(x+2)]=='1'){
			return true;
		}else{
			return false;
		}
	case 2:
		//cout<<map[y*2+1]<<" "<<(x+2)<<endl;
		if(map[y*2+1][(x+2)]=='1'){
			return true;
		}else{
			return false;
		}
	case 3:
		if(map[y*2+2][(x+2)]=='1'){
			return true;
		}else{
			return false;
		}
	}
}

bool wall_straight(){
	switch(vec){
	case 0:
		if(map[y*2+2][(x+2)+1]=='1'){
			return true;
		}else{
			return false;
		}
	case 1:
		if(map[y*2-1][(x+2)+1]=='1'){
			return true;
		}else{
			return false;
		}
	case 2:
		if(map[y*2][(x+2)-1]=='1'){
			return true;
		}else{
			return false;
		}
	case 3:
		if(map[y*2+3][(x+2)]=='1'){
			return true;
		}else{
			return false;
		}
	}
}

bool wall_rightAngle(){
	switch(vec){
	case 0:
		if(map[(y*2+1)+2][(x+2)+1]=='1'){
			return true;
		}else{
			return false;
		}
	case 1:
		if(map[(y*2+1)-1][(x+2)+1]=='1'){
			return true;
		}else{
			return false;
		}
	case 2:
		if(map[(y*2)-1][(x+2)]=='1'){
			return true;
		}else{
			return false;
		}
	case 3:
		if(map[(y*2+1)+1][(x+2)-1]=='1'){
			return true;
		}else{
			return false;
		}
	}
}



void go_straight(){
	y+=dvy[vec];
	x+=dvx[vec];
	//cout<<"move now_pos="<<y<<" "<<x<<" "<<v[vec]<<endl;
}
void go_straight_move(){
	y+=dvy[vec];
	x+=dvx[vec];
	//cout<<"move now_pos="<<y<<" "<<x<<" "<<v[vec]<<endl;
}

void solve(){
	int count=0;
	while(y!=1||x!=-1){
		if(count>100)break;
		//cout<<y<<" "<<x<<" "<<v[vec]<<endl;
		if(wall_front()){
			//cout<<"front"<<endl;
			vec++;
			vec=vec%4;
			cout<<v[vec];
		}else if(wall_straight()){
			//cout<<"straight"<<endl;
			go_straight();
			cout<<v[vec];
		}else if(wall_rightAngle()){
			//cout<<"right"<<endl;
			go_straight_move();
			if(y==1&&x==-1){
				return;
			}
			vec+=3;
			vec=vec%4;
			go_straight();
			cout<<v[vec];
		}else{
			//cout<<"turn"<<endl;
			go_straight();
			if(y==1&&x==-1){
				return;
			}
			//cout<<v[vec];
			vec+=3;
			vec=vec%4;
			go_straight_move();
			if(y==1&&x==-1){
				return;
			}
			vec+=3;
			vec=vec%4;
			go_straight();
			cout<<v[vec];
		}
		count++;
	}
}


int main(){
	string s;
	while(cin.eof()!=true){
		cin>>s;
		s="00"+s+"00";
		map.push_back(s);
	}
	map.push_front("000000000000000000000");
	map.push_front("000000000000000000000");
	map.push_back("000000000000000000000");
	map.push_back("000000000000000000000");
	/*
	for(int i=0;i<map.size();i++){
		cout<<map[i]<<endl;
	}*/
	solve();
	cout<<endl;
	return 0;
}

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

typedef vector <string> VS;

VS R;
string D = "RDLU";
const int RIGHT = 0;
const int DOWN = 1;
const int LEFT = 2;
const int UP = 3;

void dfs( int dir, int x, int y ) {
    // cout << dir << ", " << x << ", " << y << endl;
    cout << D[dir];
    if ( dir != RIGHT && x == 0 && y == 0 ) return;

    if ( dir == RIGHT ) {
        if ( y-1 >= 0 && x+1 < R[y-1].size() && R[y-1][x+1] == '1' ) {
            return dfs( UP, x+1, y-1 );
        }
        if ( x+1 < R[y].size() && R[y][x+1] == '1' ) {
            return dfs( RIGHT, x+1, y );
        }
        if ( y+1 < R.size() && x+1 < R[y+1].size() && R[y+1][x+1] == '1' ) {
            return dfs( DOWN, x+1, y+1 );
        }
    } else if ( dir == DOWN ) {
        if ( y+1 < R.size() && x < R[y+1].size() && R[y+1][x] == '1' ) {
            return dfs( RIGHT, x, y+1 );
        }
        if ( y+2 < R.size() && R[y+2][x] == '1' ) {
            return dfs( DOWN, x, y+2 );
        }
        if ( y+1 < R.size() && x-1 >= 0 && R[y+1][x-1] == '1' ) {
            return dfs( LEFT, x-1, y+1 );
        }
    } else if ( dir == LEFT ) {
        if ( y+1 < R.size()&& x < R[y+1].size() && R[y+1][x] == '1' ) {
            return dfs( DOWN, x, y+1 );
        }
        if ( x-1 >= 0 && R[y][x-1] == '1' ) {
            return dfs( LEFT, x-1, y );
        }
        if ( y-1 >= 0 && x < R[y-1].size() && R[y-1][x] == '1' ) {
            return dfs( UP, x, y-1 );
        }
    } else if ( dir == UP ) {
        if ( y-1 >= 0 && x-1 >= 0 && R[y-1][x-1] == '1' ) {
            return dfs( LEFT, x-1, y-1 );
        }
        if ( y-2 >= 0 && R[y-2][x] == '1' ) {
            return dfs( UP, x, y-2 );
        }
        if ( y-1 >= 0 && x < R[y-1].size() && R[y-1][x] == '1' ) {
            return dfs( RIGHT, x, y-1 );
        }
    }
}

int main() {
    R = VS( 9 );
    for ( int i = 0; i < 9; i++ ) {
        cin >> R[i];
    }
    dfs( 0, 0, 0 );
    cout << endl;
    return 0;
}

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

int map[11][7], type, x = 2, y = 1;

void right(void)
{
	if (map[y-1][x]){ type = 2; y -= 2; cout << "U"; }
	else if (map[y][x]){ type = 0; x += 1; cout << "R"; }
	else if (map[y+1][x]){ type = 3; y += 2; cout << "D"; }
	else { type = 1; x -= 1; cout << "L"; }
	return;
}

void left(void)
{
	if (map[y+1][x]){ type = 3; y += 2; cout << "D"; }
	else if (map[y][x-1]){ type = 1; x -= 1; cout << "L"; }
	else if (map[y-1][x]){ type = 2; y -= 2; cout << "U"; }
	else { type = 0; x += 1; cout << "R"; }
	return;
}

void up(void)
{
	if (map[y][x-1]){ type = 1; x -= 1; cout << "L"; }
	else if (map[y-1][x]){ type = 2; y -= 2; cout << "U"; }
	else if (map[y][x]){ type = 0; x += 1; cout << "R"; }
	else { type = 3; y += 2; cout << "D"; }
	return;
}

void down(void)
{
	if (map[y][x]){ type = 0; x += 1; cout << "R"; }
	else if (map[y+1][x]){ type = 3; y += 2; cout << "D"; }
	else if (map[y][x-1]){ type = 1; x -= 1; cout << "L"; }
	else { type = 2; y -= 2; cout << "U"; }
	return;
}

int main(void)
{
	string a, b;
	for (int i = 1; i <= 9; i++){
		if (i % 2 == 1){
			cin >> a;
			for (int j = 0; j < 4; j++){
				map[i][j+1] = a[j] - '0';
			}
		}
		else {
			cin >> b;
			for (int j = 0; j < 5; j++){
				map[i][j+1] = b[j] - '0';
			}
		}
	}
	
	while (!(x == 1 && y == 1)){
		switch(type){
			case 0:
				right();
				break;
			case 1:
				left();
				break;
			case 2:
				up();
				break;
			case 3:
				down();
				break;
			default:
				puts("");
				return 0;
		}
	}
	
	return 0;
}