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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
#include <cassert>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

char m[10][10];

bool end(int x, int y) {
  return (x == 1 && y == 1) || (x == 0 && y == 1) ;
}

void check(int x, int y, int d) {
  printf("x,y = %d,%d : %d\n", x, y, d);
  assert(false);
}

int main() {
  memset(m, 0, sizeof m);
  string ans = "R";
  rep(i,9) scanf(" %s", m[i]);
  rep(i,9) {
    rep(j,5) {
      m[i][j] = (m[i][j] == '1') ? 1 : 0 ;
    }
  }
  
  int x = 1, y = 0, d = 1;
  do {
    // printf("(%d,%d) : %d : %s\n", x, y, d, ans.c_str());
    switch (d) {
      case 0: {
        // up
        if (m[2*(y-1)][x-1]) {
          ans += 'L';
          d = 3;
        } else if (m[2*(y-2)+1][x]) {
          // ok
          ans += 'U';
          --y;
        } else if (m[2*(y-1)][x]) {
          // ok
          ans += 'R';
          d = 1;
          ++x; --y;
        } else {check(x,y,d);}
        break;
      }
      case 1: {
        // right
        if (m[2*(y-1)+1][x]) {
          ans += 'U';
          d = 0;  
        } else if (m[2*y][x]) {
          // ok
          ans += 'R';
          ++x;
        } else if (m[2*y+1][x]) {
          // ok
          ans += 'D';
          d = 2;
          ++x; ++y;
        } else {check(x,y,d);}
        break;        
      }
      case 2: {
        // down
        if (m[2*y][x-1]) {
          ans += 'R';
          d = 1;
        } else if (m[2*y+1][x-1]) {
          // ok
          ans += 'D';
          ++y;
        } else if (m[2*y][x-2]) {
          // ok
          ans += 'L';
          d = 3;
          --x; ++y;
        } else {check(x,y,d);}
        break;
      }
      case 3: {
        // left
        if (m[2*(y-1)+1][x-1]) {
          ans += 'D';
          d = 2;
        } else if (m[2*(y-1)][x-2]) {
          // ok
          ans += 'L';
          --x;
        } else if (m[2*(y-2)+1][x-1]) {
          // ok
          ans += 'U';
          d = 0;
          --x; --y;
        } else {check(x,y,d);}
        break;        
      }
    }
  } while (!end(x,y));
  if (x == 1 && y == 1 && d == 0) ans += 'L';
  printf("%s\n", ans.c_str());
  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define repc(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef pair<int, pii> pip;
 
 
 
const int INF = 1000000;
const double EPS = 1e-8;
const int mod = 1e9 + 7;

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

int main(){
	int p[5][5][4];
	memset(p, 0, sizeof(p));
	string s;
	rep(i, 9){
		cin>>s;
		rep(j, s.size()){
			if(s[j] == '1'){
				if(i%2 == 0){
					p[i/2][j][0] = 1;
					p[i/2][j + 1][2] = 1;
				}else{
					p[i/2][j][3] = 1;
					p[i/2 + 1][j][1] = 1;
				}
			}
		}
	}

	int dir = 0;
	s ="RULD";
	int x = 0, y = 0;
	while(1){
		if(dir == 0){
			if(p[y][x][1]){
				dir = 1;
			}else if(p[y][x][0]){

			}else if(p[y][x][3]){
				dir = 3;
			}else if(p[y][x][2]){
				dir = 2;
			}
		}else if(dir == 1){
			if(p[y][x][2]){
				dir = 2;
			}else if(p[y][x][1]){

			}else if(p[y][x][0]){
				dir = 0;
			}else if(p[y][x][3]){
				dir = 3;
			}
		}else if(dir == 2){
			if(p[y][x][3]){
				dir = 3;
			}else if(p[y][x][2]){

			}else if(p[y][x][1]){
				dir = 1;
			}else if(p[y][x][0]){
				dir = 0;
			}
		}else{
			if(p[y][x][0]){
				dir = 0;
			}else if(p[y][x][3]){

			}else if(p[y][x][2]){
				dir = 2;
			}else if(p[y][x][1]){
				dir = 1;
			}
		}
		cout<<s[dir];
		x += dx[dir];
		y += dy[dir];
		//printf(" (%d, %d)\n", x, y);
		if(x == 0 && y == 0) break;
	}
	printf("\n");
}

C++: #include <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

int dx[4] = {-1,0,1,0}, dy[4] = {0,-1,0,1};
vector<pair<int, int>> G[55];

int main() {

  rep(i, 5) {
    char x;
    rep(j, 4) {
      cin >> x;
      if(x-'0') {
        G[i * 5 + j].emplace_back(i * 5 + j + 1, 2);
        G[i * 5 + j + 1].emplace_back(i * 5 + j, 0);
      }
    }

    if(i == 4) break;

    rep(j, 5) {
      cin >> x;
      if(x-'0') {
        G[i * 5 + j].emplace_back((i + 1) * 5 + j, 3);
        G[(i + 1) * 5 + j].emplace_back(i * 5 + j, 1);
      }
    }
  }

  string const OP = "LURD";

  int y = 0, x = 0, d = 2;

  while(y != 0 || x != 0 || d != 0) {
    int le = -1, st = -1, ri = -1, dw = -1;
    for(auto && e: G[y * 5 + x]) {
      if(e.second == (d + 3) % 4) le = e.second;
      if(e.second == (d + 1) % 4) ri = e.second;
      if(e.second == d) st = e.second;
      if(e.second == (d + 2) % 4) dw = e.second;
    }
    if(le != -1) d = le;
    else if(st != -1) ;
    else if(ri != -1) d = ri;
    else d = dw;
    y += dy[d], x += dx[d];
    cout << OP[d];
  }
  cout << endl;
    
  return 0;
}