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 <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, int a ) {
    cout << D[dir];

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

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

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

using namespace std;

void move(int,int,char);
char det_angle(int,int,char);

char perm_angle[4] = {'R','U','L','D'};
int grid[5][5][4] = {0};

int main(){

	int flag;
	for(int i=0;i<9;i++){
		if(i%2 == 0){
			for(int j=0;j<4;j++){
				fscanf(stdin,"%1d",&flag);
				//cout << flag;
				if(flag == 1){
					//cout << "+";
					grid[i/2][j][0]  = 1; //R
					grid[i/2][j+1][2]= 1; //L
				}
			}
		}
		else{
			for(int j=0;j<5;j++){
				fscanf(stdin,"%1d",&flag); 
				//cout << flag;
				if(flag == 1){
					//cout << "-";
					grid[i/2][j][3]  = 1; //D
					grid[i/2+1][j][1]= 1; //U
				}
			}
			
		}
	}
	cout << 'R';
	move(0,1,'R');
	//cout << endl;
}

void move(int x,int y,char angle){
	if(x == 0 && y== 0){
		cout << endl;
		exit(0);
	}
	
	cout << angle;
	
	if(angle == 'R'){
		++y;
	}
	else if(angle == 'U'){
		--x;
	}
	else if(angle == 'L'){
		--y;
	}
	else if(angle == 'D'){
		++x;
	}
	//cout << "test" << x <<" " << y;
	move(x,y,det_angle(x,y,angle));
	//cout << angle << endl; 
}

char det_angle(int x,int y,char angle){
	
	//cout << x << y << " " << angle << endl;
	int start;
	if(angle == 'R'){
		start = 5;
	}
	else if(angle == 'U'){
		start = 6;
	}
	else if(angle == 'L'){
		start = 7;	
	}
	else if(angle == 'D'){
		start = 4;
	}
	//cout << start << endl;
	for(int i = start;start - i < 4 ;--i){
		if(grid[x][y][i%4] == 1){
			//cout << "kettei" << i <<endl ;
			return perm_angle[i%4];
		}
	}
	return 'Z';
}

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

using namespace std;

int xdir[4] = {0, 1, 0, -1}, ydir[4] = {-1, 0, 1, 0};
char dir[4] = {'U', 'R', 'D', 'L'};

int main()
{
  int l, x, y, d;
  string str;
  bool a[11][11][11][11]; // current pos[h][w], next pos[h][w]

  while(cin>>str){
    l = str.size()+1;
    y = 1;
    fill(&a[0][0][0][0], &a[l+1][0][0][0], false);

    for(int i = 1; i < l; ++i)
      if(str[i-1] == '1')
	a[0][i-1][0][i] = a[0][i][0][i-1] = true;

    for(int i = 1; i <= 8; ++i){
      cin >> str;
      if(i%2){
	for(int j = 0; j < l; ++j)
	  if(str[j] == '1') 
	    a[y-1][j][y][j] = a[y][j][y-1][j] = true;
      } else {
	for(int j = 1; j < l; ++j)
	  if(str[j-1] == '1')
	    a[y][j-1][y][j] = a[y][j][y][j-1] = true;
	y++;
      }
    }

    x = y = d = 0;
    do {
      for(int i = 3; i < 7; ++i){
	int dx = x+xdir[(d+i)%4], dy = y+ydir[(d+i)%4];
	
	if(0 <= dx && dx < l && 0 <= dy && dy < l && a[y][x][dy][dx]){
	  cout << dir[(d+i)%4];
	  // cout<<": ("<<x<<", "<<y<<") -> ("<<dx<<", "<<dy<<")"<<endl;  
	  a[y][x][dy][dx] = false;
	  x = dx;
	  y = dy;
	  d = (d+i)%4;
	  break;
	}
      }
    } while(x+y != 0);
    
    cout << endl;
  }

  return 0;
}