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 <string>

using namespace std;

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const string dir = "RDLU";

int main()
{
    string input;

    while (cin >> input) {
        bool map[5][5][4];

        // Initialization
        for (int i = 0; i < 5; i++)
            for (int j = 0; j < 5; j++)
                for (int k = 0; k < 4; k++)
                    map[i][j][k] = false;

        // Input (0,0) - (0,4)
        for (int i = 0; i < 4; i++) 
            if (input[i] == '1') {
                map[0][i][0] = true;
                map[0][i + 1][2] = true;
            }

        // Input Others
        for (int i = 0; i < 8; i++) {
            cin >> input;
            int lim;
            (i % 2) ? (lim = 4) : (lim = 5);

            for (int j = 0; j < lim; j++)
                if (input[j] == '1') {
                    if (i % 2) {
                        map[(i + 1) / 2][j][0] = true;
                        if (j)
                            map[(i + 1) / 2][j + 1][2] = true;
                    }
                    else {
                        map[i / 2][j][1] = true;
                        map[(i / 2) + 1][j][3] = true;
                    }
                }
        }

        // algorithm
        int x, y, d;

        x = y = d = 0;
        do {
            //cout << "(" << y << "," << x << "," << d << ")" << endl;
            if (map[y][x][d])
                ;
            else if (map[y][x][(d + 1) % 4]) 
                d = (d + 1) % 4;
            else if (map[y][x][(d + 3) % 4]) 
                d = (d + 3) % 4;

            map[y][x][d] = false;
            x += dx[d];
            y += dy[d];
            cout << dir[d];
        } while (x || y);

        cout << endl;
    }

    

    return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
struct man{int x,y,d;};
int main(){
  string st[9];
  int i,j,k;
  for(i=0;i<9;i++) cin >> st[i];
  bool f=false,mo=false;
  man m;
  m.x=0;m.y=0;m.d=0;
  int c=0;
  while(c<50){
    c++;
    mo=false;
    if(m.x==0&&m.y==0&&f) break;
    f=true;
    //cout << m.x<<":"<<m.y<<":"<<m.d << endl;
    if(m.d==0){
      if(st[m.y*2][m.x]=='1') {
	m.x++;
	cout << "R";
	mo=true;
	//continue;
      }
      if(m.y>0){
	if(st[m.y*2-1][m.x]=='1') {
	  m.d=3;
	  continue;
	}
      }
      
      if(st[m.y*2+1][m.x]=='1') {
	m.d=1;
	continue;
      }
      //m.d=2;
      //continue;
    }
    if(m.d==1){
      
      if(st[m.y*2+1][m.x]=='1') {
	m.y++;
	cout << "D" ;
	mo=true;
	//continue;
      }
      if(m.x<4){
	if(st[m.y*2][m.x]=='1') {
	  m.d=0;
	  continue;
	}
      }
      if(st[m.y*2][m.x-1]=='1') {
	m.d=2;
	continue;
      }
      //m.d=3;
      //continue;
    }
    if(m.d==2){
      
      if(st[m.y*2][m.x-1]=='1') {
	m.x--;
	cout << "L" ;
	mo=true;
	//continue;
      }
      if(m.y<4){
	if(st[m.y*2+1][m.x]=='1') {
	  m.d=1;
	  continue;
	}
      }
      if(st[m.y*2-1][m.x]=='1') {
	m.d=1;
	continue;
      }
      //m.d=0;
      //continue;
    }
    if(m.d==3){
      
      if(st[m.y*2-1][m.x]=='1') {
	m.y--;
	cout << "U" ;
	mo=true;
	//continue;
      }
      if(m.x>0){
	if(st[m.y*2][m.x-1]=='1') {
	  m.d=2;
	  continue;
	}
      }
      if(st[m.y*2][m.x]=='1') {
	m.d=0;
	continue;
      }
      //m.d=1;
      //continue;
    }
    if(!mo)m.d=(m.d+2)%4;
  }
  cout << endl;
  return 0;
}

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

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
char dc[] = "RDLU";

int main() {
	int g[11][11] = {};
	char c;
	for (int i=1; i<10; ++i) {
		int k = i % 2; // 0=vertical, 1=horizontal
		for (int j=1+k; j<=9-k; j+=2) {
			cin >> c;
			g[i][j] |= c - '0';
			g[i-1+k][j-k] |= c - '0';
			g[i+1-k][j+k] |= c - '0';
		}
	}
	int x=1, y=1, d=0;
	do {
		for (int t=d+3; ; ++t) {
			if (g[y + dy[t%4]][x + dx[t%4]]) {
				d = t%4;
				break;
			}
		}
		x += dx[d] * 2;
		y += dy[d] * 2;
		cout << dc[d];
	} while (x != 1 || y != 1);
	cout << endl;
	return 0;
}

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 ver[10][10], hol[10][10];
const int dx[] = {-1,0,1,0};
const int dy[] = {0,1,0,-1};
const char dir[] = {'U','R','D','L'};

void input() {
  scanf("%s", hol[1]+1);
  rep(i,4) {
    scanf("%s", ver[i+1]+1);
    scanf("%s", hol[i+2]+1);
  }
  rep(i,8) rep(j,8) {
    if (hol[i][j] == '1') hol[i][j] = 1;
    else hol[i][j] = 0;
    if (ver[i][j] == '1') ver[i][j] = 1;
    else ver[i][j] = 0;
  }
  // rep(i,8) {
  //   putchar(' ');
  //   rep(j,8) printf("%2d", hol[i][j]); puts("");
  //   rep(j,8) printf("%2d", ver[i][j]); puts("");
  // }
}

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

void update(int &x, int &y, int &d) {
  const int bx = x, by = y, bd = d;
  switch (d) {
    case 0: {
      if (hol[y][x]) d = 3;
      else if (ver[y-1][x+1]) --y;
      else if (hol[y][x+1]) { ++x; --y; d = 1; }
      else { d = 2; ++x; }
      break;
    }
    case 1: {
      if (ver[y][x+1]) d = 0;
      else if (hol[y+1][x+1]) ++x;
      else if (ver[y+1][x+1]) { ++x; ++y; d = 2; }
      else { d = 3; ++y; }
      break;
    }
    case 2: {
      if (hol[y+1][x]) d = 1;
      else if (ver[y+1][x]) ++y;
      else if (hol[y+1][x-1]) { --x; ++y; d = 3; }
      else { d = 0; --x; }
      break;
    }
    case 3: {
      if (ver[y][x]) d = 2;
      else if (hol[y][x-1]) --x;
      else if (ver[y-1][x]) { --x; --y; d = 0; }
      else { d = 1; --y; }
      break;
    }
  }
  if (bx == x && by == y && bd == d) {
    printf("%d %d %d\n", x, y, d);
    assert(false);
  }
}

void solve() {
  int x = 1, y = 0, d = 1;
  string ans = "R";
  do {
    // printf("%d,%d - %d : %s\n", x, y, d, ans.c_str());
    update(x, y, d);
    ans += dir[d];
  } while (!is_end(x,y,d));
  printf("%s\n", ans.c_str());
}

int main() {
  input();
  solve();
  return 0;
}