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<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;
      int hx = x + dx[(dir+1)%4],hy = y + dy[(dir+1)%4];
      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')));
    }
}

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

C++: #include <iostream>

using namespace std;

enum Direction {R, L, U, D};

bool input(char b[][5])
{
	char dummy;
	for (int i=0; i<9; i++) {
		for (int j=0; j<5; j++) {
			if ((i&1)==0 && j==4) continue;
			if ( !(cin >> b[i][j]) ) return false;
		}
		//cin >> dummy;
	}
	return true;
}

int main()
{
	char board[9][5];
	input(board);
	
	pair<int, int> curr_pos = (board[1][0] == '1') ? pair<int,int>(1,0) : pair<int,int>(0,0);
	enum Direction curr_dir = (board[1][0] == '1') ? D : R;
	if (curr_dir == D) cout << "D";
	else cout << "R";
	
	do {
		switch (curr_dir) {
		case R:
			// priority : U > R > D
			if ( curr_pos.first > 0 && board[curr_pos.first-1][curr_pos.second+1] == '1' ) {
				curr_dir = U; cout << "U"; curr_pos.first--; curr_pos.second++;
			} else if ( curr_pos.second < 3 && board[curr_pos.first][curr_pos.second+1] == '1' ){
				curr_dir = R; cout << "R"; curr_pos.second++;
			} else {
				curr_dir = D; cout << "D"; curr_pos.first++; curr_pos.second++;
			} 
			break;
		case L:
			// priority : D > L > U
			if ( curr_pos.first < 8 && board[curr_pos.first+1][curr_pos.second] == '1' ) {
				curr_dir = D; cout << "D"; curr_pos.first++;
			} else if ( curr_pos.second > 0 && board[curr_pos.first][curr_pos.second-1] == '1' ) {
				curr_dir = L; cout << "L"; curr_pos.second--;
			} else {
				curr_dir = U; cout << "U"; curr_pos.first--;
			}
			break;
		case U:
			// priority : L > U > R
			if ( curr_pos.second > 0 && board[curr_pos.first-1][curr_pos.second-1] == '1' ) {
				curr_dir = L; cout << "L"; curr_pos.first--; curr_pos.second--;
			} else if ( curr_pos.first > 2 && board[curr_pos.first-2][curr_pos.second] == '1' ) {
				curr_dir = U; cout << "U"; curr_pos.first-=2;
			} else {
				curr_dir = R; cout << "R"; curr_pos.first--;
			}
			break;
		case D:
			// priority : R > D > L
			if ( board[curr_pos.first+1][curr_pos.second] == '1' ) {
				curr_dir = R; cout << "R"; curr_pos.first++;
			} else if ( curr_pos.first < 6 && board[curr_pos.first+2][curr_pos.second] == '1' ) {
				curr_dir = D; cout << "D"; curr_pos.first+=2;
			} else {
				curr_dir = L; cout << "L"; curr_pos.first++; curr_pos.second--;
			}
			break;
		}
	} while ( curr_pos.first != 0 || curr_pos.second != 0 );
	
	cout << endl;
	
	return 0;
}

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

using namespace std;


int main(){

	while(1){
		char yoko[10][10];
		char tate[10][10];
		if(cin.eof())
			break;

		for(int i = 0; i < 5; i++){
			for(int j = 0; j < 4; j++){
				cin>>yoko[i][j];
			}
			for(int j = 0; j < 5; j++){
				cin>>tate[i][j];
			}
		}
		// 0,1,2,3ÅEAºA¶Aã
		int angle=0;
		int px,py;
		px=py=0;
		while(1){
			if(angle==0){
				if(px!=4&&yoko[py][px]=='1'){
					cout<<"R";
					px++;
				}
				else{
					// ãÖ
					if(py!=0&&tate[py-1][px]=='1'){
						py--;
						angle=3;
						cout<<"U";
					}
					// ºÉÇª êÎAºÖ
					else if(py!=4&&tate[py][px]=='1'){
						py++;
						angle=1;
						cout<<"D";
					}
					else{
						px--;
						angle=2;
						cout<<"L";
					}
				}
			}
			// º
			else if(angle==1){
				if(py!=4&&tate[py][px]=='1'){
					cout<<"D";
					py++;
				}
				else{
					// ºÉÇª³¯êÎA½]
					if(px!=4&&yoko[py][px]=='1'){
						cout<<"R";
						angle=0;
						px++;
					}
					else if(px!=0&&yoko[py][px-1]=='1'){
						cout<<"L";
						angle=2;
						px--;
					}
					else{
						py--;
						angle=3;
						cout<<"U";
					}
				}
			}
			// ¶
			else if(angle==2){
				if(px!=0&&yoko[py][px-1]=='1'){
					cout<<"L";
					px--;
				}
				else{
					// ºÉÇª êÎAºÖ
					if(py!=4&&tate[py][px]=='1'){
						py++;
						angle=1;
						cout<<"D";
					}
					// ãÖ
					else if(py!=0&&tate[py-1][px]=='1'){
						py--;
						angle=3;
						cout<<"U";
					}
					else{
						px++;
						angle=0;
						cout<<"R";
					}
				}
			}
			// ã
			else if(angle==3){
				if(py!=0&&tate[py-1][px]=='1'){
					cout<<"U";
					py--;
				}
				else{
					// ºÉÇª³¯êÎA½]
					if(px!=0&&yoko[py][px-1]=='1'){
						cout<<"L";
						angle=2;
						px--;
					}
					else if(px!=4&&yoko[py][px]=='1'){
						cout<<"R";
						angle=0;
						px++;
					}
					else{
						py++;
						angle=1;
						cout<<"D";
					}
				}
			}
			if(px==0&&py==0)
				break;
}
cout<<endl;
}
			
return 0;
}