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<bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < (n); i++)
using namespace std;
string s[10];
int x, y, d = 1;
bool fU() {
	if (y == 0)return 0;
	else return s[y * 2 - 1][x] == '1';
}
void mU() { cout << "U"; y--; return; }
bool fD() {
	if (y == 4)return 0;
	else return s[y * 2 + 1][x] == '1';
}
void mD() { cout << "D"; y++; return; }
bool fL() {
	if (x == 0)return 0;
	else return s[y * 2][x - 1] == '1';
}
void mL() { cout << "L"; x--; return; }
bool fR() {
	if (x == 4)return 0;
	else return s[y * 2][x] == '1';
}
void mR() { cout << "R"; x++; return; }
signed main() {
	for0(i, 9)cin >> s[i];
	mR();
	while (x + y > 0) {
		for0(i, 4) {
			if ((i + 3 + d) % 4 == 0) {
				if (fU()) { mU(); d = 0; break; }
			}
			else if ((i + 3 + d) % 4 == 1) {
				if (fR()) { mR(); d = 1; break; }
			}
			else if ((i + 3 + d) % 4 == 2) {
				if (fD()) { mD(); d = 2; break; }
			}
			else if ((i + 3 + d) % 4 == 3) {
				if (fL()) { mL(); d = 3; break; }
			}
		}
	}
	printf("\n");
}

C++: // 今向いている方向にとっての左から始めて、時計回りに壁を探して、最初にみつけた壁の方向に進む
#include <fstream>
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;
struct Direction {
  bool u, d, r, l;
};

void dump_Direction(Direction di) {
  cout << "[" << di.u << di.r << di.d << di.l << "]";
}



int main() {
  // ifstream cin("../test.txt");
  Direction g[5][5];
  string s;
  for (int i = 0; i < 9; i++) {
    getline(cin, s);
    if (i % 2 == 0) {
      for (int j = 0; j < 4; j++) {
        int k = i / 2;
        g[k][j].r = (s[j] == '1');
        g[k][j+1].l = (s[j] == '1');
      }
    } else {
      for (int j = 0; j < 5; j++) {
        int k = i / 2;
        g[k][j].d = (s[j] == '1');
        g[k+1][j].u = (s[j] == '1');
      }
    }
  }
  // 表示用
  // for (int i = 0; i < 5; i++) {
  //   for (int  j = 0; j < 5; j++) {
  //     dump_Direction(g[i][j]);
  //   }
  //   cout << endl;
  // }

  int x = 0;
  int y = 0;
  int d = 0; // 0: u, 1: r, 2: d, 3: l
  int dx[] = {0,1,0,-1};
  int dy[] = {-1,0,1,0};
  char c[] = {'U','R','D','L'};
  while (true) {
    bool dir[] = {g[y][x].u, g[y][x].r, g[y][x].d, g[y][x].l};
    // dump_Direction(g[y][x]);
    int i = 0;
    for (;i < 4; i++) {
      if (dir[(i+d)%4]) break;
    }
    int j = (i+d)%4;
    // cout << j;
    x += dx[j];
    y += dy[j];
    cout << c[j];
    d = (j + 3) % 4;
    if (!(x|y)) break;
  }
  cout << endl;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit
#include <cstdio>	// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define TOP 0
#define RIGHT 1
#define BOTTOM 2
#define LEFT 3
#define DEBUG 0
#define DEBUG2 0
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
string FILE_NAME = "testcase.Path_on_a_Grid";
string NAME;
string itos (int n )
{
	stringstream ss;
	ss << n;

	return ss.str();
}
int grid[15][15];
const int dr[] = {-1, 0, 1, 0 };
const int dc[] = { 0, 1, 0,-1 };
const char Dir[] = { 'U','R','D','L'};

string res;
void touch_wall (int row, int col, int dir, int hand )
{
	if ((1<<hand & grid[row][col] ) != 0 )
		res += Dir[dir];	
}

int main()
{
//	cut here before submit 
#if DEBUG
	NAME = FILE_NAME;
	int CNT = 1;
	NAME += itos (CNT );
	while (freopen (NAME.c_str() , "r", stdin ) != NULL ) {
#endif
	memset (grid, 0, sizeof (grid ) );

	for (int i = 1; i <= 9; i++ ){
		string s = "";
		cin >> s;
		rep (j, s.length() ){
			if (i % 2 != 0 ){
				if (s[j] == '1' ){
					grid[i/2][j+1] |= 1<<BOTTOM;
					grid[(i+1)/2][j+1] |= 1<<TOP;
				} // end if
			}else{
				if (s[j] == '1' ){
					if (j == 0 ){
						grid[i/2][j+1] |= 1<<LEFT;
					}else{
						grid[i/2][j+1] |= 1<<LEFT;
						grid[i/2][j] |= 1<<RIGHT;
					} // end if
				} // end if
			} // end if
		} // end rep
	} // end for
#if DEBUG2
	rep (i, 10 ){
		rep (j, 10 ){
			cout << setw(2) << grid[i][j];
		} // end rep
		cout << endl;
	} // end rep
#endif

	int row = 0, col = 1, dir = RIGHT;
	int hand = (dir+1)%4;
	res = "";
	do{
		touch_wall (row, col, dir, hand );
		if ((1<<hand & grid[row][col] ) == 0 ){	// 右手の壁がなくなった、なくなった方向に回転
			dir = hand;
		}else
		if ((1<<dir & grid[row][col] ) != 0 ){	
			while ((1<<dir & grid[row][col] ) != 0 ){// 右手の壁があったとしても前に進めない
				dir = (4+dir-1)%4;
				touch_wall (row, col, dir, hand );
			} // end while
		} // end if
		row = row + dr[dir];
		col = col + dc[dir];
		hand = (dir+1)%4;
#if DEBUG2
		cout << '(' << row << ',' << col << ')' << " dir: " << dir << endl;
#endif
	}while (!(row == 0 && col == 0 ) ); // end while
	cout << res << endl;

#if DEBUG
	CNT++;	// cut here before submit
	NAME = FILE_NAME;
	NAME += itos (CNT );
	} // end loop; cut here before submit
#endif
			
	return 0;
}

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

using namespace std;

int can[10][10][4];

// RDLU
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

string answer;
int dfs(int y,int x,int py,int px,int d){

	if( py != -1 ){
		if( y == py ){
			if( x - px > 0 ) answer += "R"; else answer += "L";
		}else{
			if( y - py > 0 ) answer += "D"; else answer += "U";
		}
	}
	if( py != -1 && x == 0 && y == 0 ) return 0;
	//cout << y << " " << x << " " << can[y][x][0] << " " << can[y][x][1] << " " << can[y][x][2] << " " << can[y][x][3] << " " << endl;
	
	for(int i = 0 ; i < 4 ; i++){
		if( can[y][x][(i+d)%4]  ){
			int tx = x + dx[(i+d)%4];
			int ty = y + dy[(i+d)%4];
			if( tx == px && ty == py ) continue;
			can[y][x][(i+d)%4] = 0;
			dfs(ty,tx,y,x,(i+d)%4);
			return 0;
		}
	}
}// RDLU
int main(){

	for(int i = 0 ; i < 9 ; i++){
		if( i % 2 ){
			for(int j = 0 ; j < 5 ; j++){
				char c;
				cin >> c;
				if( c == '1' ){
					can[i/2][j][1] = 1;
					can[i/2+1][j][3] = 1;
				}
			}
		}else{
			for(int j = 0 ; j < 4 ; j++){
				char c;
				cin >> c;
				if( c == '1' ){
					can[i/2][j][0] = 1; 
					can[i/2][j+1][2] = 1;
				}
			}
		}
	}
	dfs(0,0,-1,-1,0);
	cout << answer << endl;
}