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 <cstdio>
#include <cstring>
#include <vector>
#define RIGHT 1
#define LEFT -1
#define UP 2
#define DOWN -2
using namespace std;

int main(){
	int i,j,state,sy=0,sx=1,t_state;
	char row[5][4],col[4][5];

	cin>>row[0];
	for(i=0;i<4;i++){
		cin>>col[i];
		cin>>row[i+1];
	}

	for(i=0;i<5;i++){
		for(j=0;j<4;j++){
			row[i][j]=row[i][j]-'0';
		}
	}
	for(i=0;i<5;i++){
		for(j=0;j<4;j++){
			col[j][i]=col[j][i]-'0';
		}
	}

	cout<<"R"<<flush;
	state=RIGHT;
	while(sy || sx){
		switch(state){
			case RIGHT:
				if(sy>0 && col[sy-1][sx]){
					cout<<"U"<<flush;
					t_state=UP;
					sy--;
				}else if(sx<4 && row[sy][sx]){
					cout<<"R"<<flush;
					t_state=RIGHT;
					sx++;
				}else if(sy<4 && col[sy][sx]){
					cout<<"D"<<flush;
					t_state=DOWN;
					sy++;
				}else if(sx>0 && row[sy][sx-1]){
					cout<<"L"<<flush;
					t_state=LEFT;
					sx--;
				}
				break;
			case LEFT:
				if(sy<4 && col[sy][sx]){
					cout<<"D"<<flush;
					t_state=DOWN;
					sy++;
				}else if(sx>0 && row[sy][sx-1]){
					cout<<"L"<<flush;
					t_state=LEFT;
					sx--;
				}else if(sy>0 && col[sy-1][sx]){
					cout<<"U"<<flush;
					t_state=UP;
					sy--;
				}else if(sx<4 && row[sy][sx]){
					cout<<"R"<<flush;
					t_state=RIGHT;
					sx++;
				}
				break;
			case UP:
				if(sx>0 && row[sy][sx-1]){
					cout<<"L"<<flush;
					t_state=LEFT;
					sx--;
				}else if(sy>0 && col[sy-1][sx]){
					cout<<"U"<<flush;
					t_state=UP;
					sy--;
				}else if(sx<4 && row[sy][sx]){
					cout<<"R"<<flush;
					t_state=RIGHT;
					sx++;
				}else if(sy<4 && col[sy][sx]){
					cout<<"D"<<flush;
					t_state=DOWN;
					sy++;
				}
				break;
			case DOWN:
				if(sx<4 && row[sy][sx]){
					cout<<"R"<<flush;
					t_state=RIGHT;
					sx++;
				}else if(sy<4 && col[sy][sx]){
					cout<<"D"<<flush;
					t_state=DOWN;
					sy++;
				}else if(sx>0 && row[sy][sx-1]){
					cout<<"L"<<flush;
					t_state=LEFT;
					sx--;
				}else if(sy>0 && col[sy-1][sx]){
					cout<<"U"<<flush;
					t_state=UP;
					sy--;
				}
				break;
		}
		state=t_state;
	}

	cout<<endl;
	return 0;
}

C++: #include<iostream>
#include<cassert>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
#define MAX 100 
using namespace std;

struct You
{//手の位置は自分の座標にdx[(dir+1)%4],dy[(dir+1)%4]を加えた場所
  int x,y,dir;
  You(int x=-inf,int y=-inf):x(x),y(y),dir(0){}
};

char G[MAX][MAX];
int dx[] = {+1,+0,-1,+0};
int dy[] = {+0,+1,+0,-1};

void init()
{
  rep(i,MAX)rep(j,MAX)G[i][j] = '.';
}

void makeGraph()
{
  string line;
  int x;
  REP(y,1,10)
    {//odd -> yoko, even -> tate
      cin >> line;
      x = (y%2?1:0);
      rep(i,line.size())
	{
	  if(line[i] == '1')
	    {
	      G[y][x] = (y%2?'-':'|');
	      if(y%2) G[y][x-1] = G[y][x+1] = 'o';
	      else    G[y+1][x] = G[y-1][x] = 'o';
	    }
	  x += 2;
	}
    }
}

void print()
{
  rep(i,11)
    {
      rep(j,11)
	{
	  cout << G[i][j];
	}
      cout << endl;
    }
  cout << endl;
}

void compute()
{
  You you(0,0);
  bool fir = true;
  while(true)
    {
      int x = you.x,y = you.y,dir = you.dir;
      //cout << "cur  | (" << x << "," << y << ") = " << G[y][x] << endl;
      int hx = x + dx[(dir+1)%4],hy = y + dy[(dir+1)%4];
      //cout << "hand | (" << hx << "," << hy <<") = " << G[hy][hx]<< endl;
      if(!fir && hx == 0 && hy == 1)
	{
	  cout << '\n';
	  return;
	}
      fir = false;

      int nx = x + dx[dir],ny = y + dy[dir];
      hx += dx[dir],hy += dy[dir];
      assert(G[ny][nx] != 'o');

      if(G[ny][nx] == '|' || G[ny][nx] == '-')
	{
	  dir = (dir + 3)%4;
	  you.dir = dir;
	}
      else if(G[hy][hx] == '.')
	{
	  dir = (dir + 1)%4;
	  you.x = nx + dx[dir], you.y = ny + dy[dir],you.dir = dir;	  
	}
      else if(G[hy][hx] == 'o' || G[hy][hx] == '-' || G[hy][hx] == '|')
	{
	  you.x += dx[dir],you.y += dy[dir];
	}

      hx = you.x + dx[(dir+1)%4], hy = you.y + dy[(dir+1)%4];

      if(G[hy][hx] != 'o')
	cout << (dir==0?'R':(dir==1?'D':(dir==2?'L':'U')));
      //cout << endl;
    }
}

int main()
{
  init();
  makeGraph();
  compute();
  //print();
  return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
string ans="";
bool a[5][5][4] = {{{0}}};
int main(){
    string str;
    for(int i=0;i<9;i++){
        if(i%2==0){
            cin>>str;
            for(int j=0;j<4;j++){
                if(str[j]=='1'){

                    a[i/2][j][1] = true;
                    a[i/2][j+1][3] = true;
                    //cout<<"-("<<i/2<<" ,"<<j<<")("<<i/2<<" ,"<<j+1<<")"<<endl;
                }

            }
        }
        else{
            cin>>str;
            for(int j=0;j<5;j++){
                if(str[j]=='1'){
                    a[i/2][j][2] = true;
                    a[i/2+1][j][0] = true;
                    //cout<<"|("<<i/2<<" ,"<<j<<")("<<i/2+1<<" ,"<<j<<")"<<endl;
                }
				
            }
        }
    }
	cout<<"R";
		int x=1,y=0,way=1;
		while(1){
			if(x==0&&y==0)break;
			if(way == 0){
				if(x!=0&&a[y][x][3]){
					cout<<"L";
					x--;
					way = 3;
				}
				else if(y!=0&&a[y][x][0]){
					cout<<"U";
					y--;
					way = 0;
				}
				else if(x!=4&&a[y][x][1]){
					cout<<"R";
					x++;
					way = 1;
				}
				else if(y!=4&&a[y][x][2]){
					cout<<"D";
					y++;
					way = 2;
				}
			}
			else if(way == 1){
				if(y!=0&&a[y][x][0]){
					cout<<"U";
					y--;
					way = 0;
				}
				else if(x!=4&&a[y][x][1]){
					cout<<"R";
					x++;
					way = 1;
				}
				else if(y!=4&&a[y][x][2]){
					cout<<"D";
					y++;
					way = 2;
				}
				else if(x!=0&&a[y][x][3]){
					cout<<"L";
					x--;
					way = 3;
				}
			}
			else if(way == 2){
				if(x!=4&&a[y][x][1]){
					cout<<"R";
					x++;
					way = 1;
				}
				else if(y!=4&&a[y][x][2]){
					cout<<"D";
					y++;
					way = 2;
				}
				else if(x!=0&&a[y][x][3]){
					cout<<"L";
					x--;
					way = 3;
				}
				else if(y!=0&&a[y][x][0]){
					cout<<"U";
					y--;
					way = 0;
				}
			}
			else if(way == 3){
				if(y!=4&&a[y][x][2]){
					cout<<"D";
					y++;
					way = 2;
				}
				else if(x!=0&&a[y][x][3]){
					cout<<"L";
					x--;
					way = 3;
				}
				else if(y!=0&&a[y][x][0]){
					cout<<"U";
					y--;
					way = 0;
				}
				else if(x!=4&&a[y][x][1]){
					cout<<"R";
					x++;
					way = 1;
				}
			}
		}
    
	cout<<endl;
    return 0;
}