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 <string>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

namespace std {
    bool operator<(const P a, const P b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

#define S 6
// right, down, left, up
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

int const MOD = 1000000007;

int main() {
    bool board[S][S][4] = {};
    // rep(i,0,S) board[i][S-1][0] = true; // right
    // rep(i,0,S) board[S-1][i][1] = true; // down
    // rep(i,0,S) board[i][0][2]   = true; // left
    // rep(i,0,S) board[0][i][3]   = true; // up

    rep(i,0,9) {
        int l, n;
        if(i % 2 == 0) l = 4;
        else l = 5;
        rep(j,0,l) {
            scanf("%1d", &n);
            if(n == 1) {
                if(i % 2 == 0) {
                    board[i/2][j+1][1] = true;
                    board[i/2+1][j+1][3] = true;
                }
                else {
                    board[i/2+1][j][0] = true;
                    board[i/2+1][j+1][2] = true;
                }
            }
        }
    }

    string d = "RDLU";
    string ret;
    int dir = 0;
    int nx = 0, ny = 1;
    int cas = 1;
    while(1) {
        int x, y;
        // printf("test: board[%d][%d][%d] = %d\n", nx, ny, (dir+1)%4, board[nx][ny][(dir+1)%4] ? 1 : 0);
        x = nx + dx[dir], y = ny + dy[dir];
        if(board[nx][ny][(dir + 1) % 4] == 0) {
            // printf("case 1: (%d, %d)\n", nx, ny);
            dir = (dir + 1) % 4;
            nx = nx + dx[dir], ny = ny + dy[dir];
            // ret += d[dir];
            continue;
        }
        if(board[nx][ny][dir] == 1) {
            // printf("case 2: (%d, %d)\n", nx, ny);
            if(cas == 1) ret += d[dir];
            dir = (dir - 1 + 4) % 4;
            ret += d[dir];
            cas = 2;
            continue;
        }
        ret += d[dir];
        nx = x, ny = y;
        if(nx == 1 && ny == 1 && dir == 2) break;
        if(nx == 1 && ny == 0 && dir == 3) break;
    }
    // printf("endx: %d, endy: %d, dir = %d\n", nx, ny, dir);
    cout << ret << endl;
    return 0;
}

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

int main()
{
  char sidemap[5][4];
  char upmap[4][5];
  int x=0,y=0;
  for(int i=0;i<9;i++)
    {
      if(i%2==0)
	{
	  for(int j=0;j<4;j++)
	      cin>>sidemap[i/2][j];
	}
      else
	{
	  for(int j=0;j<5;j++)
	    cin>>upmap[i/2][j];
	}
    }
  /*
  for(int i=0;i<5;i++,cout<<endl)
    for(int j=0;j<4;j++)
      {
	cout<<sidemap[i][j];
      }

  for(int i=0;i<4;i++,cout<<endl)
    for(int j=0;j<5;j++)
      {
	cout<<upmap[i][j];
      }
  */
  char move='R';
  do{
    //cout<<"now:"<<x<<","<<y;
    //    cout<<"X,y="<<x<<","<<y<<endl;
    //次の移動方向
    if(move=='L')
      {
	if(x<4&&upmap[x][y]=='1')
	  move='D';
	else if(y>0 && sidemap[x][y-1]=='1')
	  move='L';
	else if(x>0 && upmap[x-1][y]=='1')
	  move='U';
	else
	  move='R';
      }
    else if(move=='R')
      {
	if(x>0&&upmap[x-1][y]=='1')
	  move='U';
	else if(y<4 && sidemap[x][y]=='1')
	  move='R';
	else if(x<4&&y<5&&upmap[x][y]=='1')
	  move='D';
	else
	  move='L';
      }
    else if(move=='U')
      {
	if(y>0&&sidemap[x][y-1]=='1')
	  move='L';
	else if(x>0&&upmap[x-1][y]=='1')
	  move='U';
	else if(x<5&&y<4&&sidemap[x][y]=='1')
	  move='R';
	else
	  move='D';
      }
    else if(move=='D')
      {
	if(x<5&&y<4&&sidemap[x][y]=='1')
	  move='R';
	else if(x<4&&upmap[x][y]=='1')
	  move='D';
	else if(y>0&&sidemap[x][y-1]=='1')
	  move='L';
	else 
	  move='U';
      }
    //次の移動方向
    if(move=='L')
      {
	y--;
      }
    else if(move=='R')
      {
	y++;
      }
    else if(move=='U')
      {
	x--;
      }
    else if(move=='D')
      {
	x++;
      }
      
      cout<<move;
      ///      cout<<endl;
  }while(x!=0||y!=0);
  cout<<endl;
}

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

using namespace std;

vector< vector<int> > map(11, vector<int>(7));
int direction = 0;   //R:0 L:1 U:2 D:3
int x = 2, y = 1;
char a[4], b[5];


void init(){
	for (int i = 1; i <= 9; i++)
	{
		if (i % 2)
		{
			cin >> a;
			for (int j = 0; j < 4; ++j)map[i][j + 1] = char(a[j]) - '0';
		}
		else 
		{
			cin >> b;
			for (int j = 0; j < 5; ++j)map[i][j + 1] = char(b[j]) - '0';
		}
	}
}

void Right()
{
	if (map[y - 1][x])direction = 2, y -= 2, cout << 'U';
	else if (map[y][x])direction = 0, x += 1, cout << 'R';
	else if (map[y + 1][x])direction = 3, y += 2, cout << 'D';
	else  direction = 1, x -= 1, cout << 'L';
}

void Left()
{
	if (map[y + 1][x])direction = 3, y += 2, cout << 'D';
	else if (map[y][x - 1])direction = 1, x -= 1, cout << 'L';
	else if (map[y - 1][x])direction = 2, y -= 2, cout << 'U';
	else direction = 0, x += 1, cout << 'R';
}

void Up()
{
	if (map[y][x - 1])direction = 1, x -= 1, cout << 'L';
	else if (map[y - 1][x])direction = 2, y -= 2, cout << 'U';
	else if (map[y][x])direction = 0, x += 1, cout << 'R';
	else direction = 3, y += 2, cout << 'D';
}

void Down()
{
	if (map[y][x])direction = 0, x += 1, cout << 'R';
	else if (map[y + 1][x])direction = 3, y += 2, cout << 'D';
	else if (map[y][x - 1])direction = 1, x -= 1, cout << 'L';
	else direction = 2, y -= 2, cout << 'U';
}


void solve()
{
	while (!(x == 1 && y == 1))
	{
		switch (direction)
		{
			case 0: Right(); break;
			case 1: Left(); break;
			case 2: Up(); break;
			case 3: Down(); break;
			default: return;
		}
	}
}

int main(){
	init();

	cout << 'R';
	solve();
	cout << endl;
	return(0);
}