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>
#define N 10
using namespace std;

bool h[N][N]; // setinel
bool v[N][N];
char dir = 'R';
int mx = 1;
int my = 1;

bool left(){
	if(h[my][mx-1]){
		mx--;
		dir = 'L';
		return true;
	}
	return false;
}

bool right(){
	if(h[my][mx]){
		mx++;
		dir = 'R';
		return true;
	}
	return false;
}

bool up(){
	if(v[my-1][mx]){
		my--;
		dir = 'U';
		return true;
	}
	return false;
}

bool down(){
	if(v[my][mx]){
		my++;
		dir = 'D';
		return true;
	}
	return false;
}

int main(){
	string str, ans = "";
	int i, j, len;

	i = j = 1;
	while(cin >> str){
		if(i == 1) len = str.size();
		if(str.size() == len){
			for (int k = 0; k < str.size(); k++) {
				h[i][k+1] = str[k] == '1' ? true : false;
			}
			i++;
		}else{
			for (int k = 0; k < str.size(); k++) {
				v[j][k+1] = str[k] == '1' ? true : false;
			}
			j++;
		}
	}
	
	do{
		if (dir == 'L') {
			if(down()){
			}else if(left()){
			}else if(up()){
			}
		}else if (dir == 'R') {
			if(up()){
			}else if(right()){
			}else if(down()){
			}
		}else if (dir == 'U') {
			if(left()){
			}else if(up()){
			}else if(right()){
			}
		}else if (dir == 'D') {
			if(right()){
			}else if(down()){
			}else if(left()){
			}
		}
		ans += dir;
	}while(!(mx == 1 && my == 1));

	cout << ans << 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=1;m.y=0;m.d=0;
  int c=0;
  cout << "R";
  while(1){
    c++;
    mo=false;
    
    if(m.x==1&&m.y==1&&m.d==2) {
      //cout << "L";
      break;
    }
    if(m.x==0&&m.y==1&&f) {
      //cout << "U";
      break;
    }
    f=true;
    
    //cout << m.x<<":"<<m.y<<":"<<m.d << endl;
    if(m.d==0){
      if(m.y>0){
	if(st[m.y*2-1][m.x]=='1') {
	  cout << "U";
	  m.d=3;
	  continue;
	}
      }
      if(m.y<5){
	if(st[m.y*2][m.x]=='1') {
	  m.x++;
	  cout << "R";
	  continue;
	}
      }
      if(m.y<4){
	if(st[m.y*2+1][m.x]=='1') {
	  m.x++;
	  m.y++;
	  cout << "D";
	  m.d=1;
	  continue;
	}
      }
      m.y++;
      cout << "L";
      m.d=2;
      continue;
    }
    
    if(m.d==1){
      if(m.y<5){
	if(st[m.y*2][m.x-1]=='1') {
	  cout <<"R";
	  m.d=0;
	  continue;
	}
      }
      if(m.x>0&&m.y<4){
	if(st[m.y*2+1][m.x-1]=='1') {
	  m.y++;
	  cout << "D" ;
	  mo=true;
	  continue;
	}
      }
      if(m.x>1&&m.y<5){
	if(st[m.y*2][m.x-2]=='1') {
	  m.x--;
	  m.y++;
	  cout << "L";
	  m.d=2;
	  continue;
	}
      }
      m.x--;
      cout << "U";
      m.d=3;
      continue;
    }
    if(m.d==2){
      if(m.x>0){
	if(st[m.y*2-1][m.x-1]=='1') {
	  cout << "D";
	  m.d=1;
	  continue;
	}
      }
      if(m.x>1&&m.y>0){
	if(st[(m.y-1)*2][m.x-2]=='1') {
	  m.x--;
	  cout << "L" ;
	  mo=true;
	  continue;
	}
      }
      if(m.x>0&&m.y>1){
	if(st[(m.y-1)*2-1][m.x-1]=='1') {
	  m.x--;
	  m.y--;
	  cout << "U";
	  m.d=3;
	  continue;
	}
      }
      m.y--;
      cout << "R";
      m.d=0;
      continue;
    }
    if(m.d==3){

      if(m.y>0){
	if(st[(m.y-1)*2][m.x-1]=='1') {
	  cout << "L";
	  m.d=2;
	  continue;
	}
      }
      if(m.y>1){
	if(st[(m.y-1)*2-1][m.x]=='1') {
	  m.y--;
	  cout << "U" ;
	  mo=true;
	  continue;
	}
      }
      if(m.y>0){
	if(st[(m.y-1)*2][m.x]=='1') {
	  m.x++;
	  m.y--;
	  cout << "R";
	  m.d=0;
	  continue;
	}
      }
      m.x++;
      cout << "D";
      m.d=1;
      continue;
    }
    //if(!mo)m.d=(m.d+2)%4;
  }
  
  cout  << endl;
  return 0;
}

C++: #include<stdio.h>
char f[6][6],i,j,a,y,x,p;
int main()
{
	for(;i<9;++i){
		scanf("%s",f[5]);
		for(j=0;j<4+i%2;++j){
			a=f[5][j]-48;
			f[i/2][j]|=a<<(1+i%2);
			f[i/2+i%2][j+!(i%2)]|=a<<3-i%2*3;
		}
	}
	do{
		while(!((f[y][x]>>(p=(p+1)%4))&1));
		putchar("URDL"[p]);
		x+=p?2-p:0;
		y+=p==3?0:p-1;
		p=(p+2)%4;
	}while(y||x||f[0][0]==6&&p==3);
	return!puts(""); 
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;


int main() {
	int g[100][100];
	memset(g, 0, sizeof(g));
	rep(i, 9) rep(j, 4 + i % 2) {
		char c;
		cin >> c;
		g[i + 1][j * 2 + (i + 1) % 2 + 1] = c - '0';
	}
	int dx[] = {0, 1, 0, -1};
	int dy[] = {-1, 0, 1, 0};
	char c[] = "URDL";
	int x = 2, y = 0, v = 1;
	do {
		cout << c[v];
		int pv = (v - 1 + 4) % 4;
		int nv = (v + 1) % 4;
		
		if (g[y + dy[v]][x + dx[v]] == 1) {
			v = pv;
		}
		else if (g[y + dy[v] * 2 + dy[nv]][x + dx[v] * 2 + dx[nv]] == 1) {
			x += dx[v] * 2;
			y += dy[v] * 2;
		}
		else {
			x += dx[v] * 2;
			x += dx[nv] * 2;
			y += dy[v] * 2;
			y += dy[nv] * 2;
			v = nv;
		}
		if (x == 0 && y == 0) break;
		if (x == 2 && y == 0) break;
	} while(true);
	cout << endl;
	
	return 0;
}

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

bool wall[5][5][4];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int main(){
	string s;
	for(int i = 0; i < 9; ++i){
		cin >> s;

		if(i % 2 == 0){
			for(int j = 0; j < 4; ++j){
				if(s[j] == '1'){
					wall[j][i / 2][0] = wall[j + 1][i / 2][2] = true;
				}
			}
		}
		else{
			for(int j = 0; j < 5; ++j){
				if(s[j] == '1'){
					wall[j][i / 2][1] = wall[j][i / 2 + 1][3] = true;
				}
			}
		}
	}

	s.clear();
	int x = 0, y = 0, dir = 0;
	do{
		s += "RDLU"[dir];
		x += dx[dir];
		y += dy[dir];

		if(wall[x][y][(dir + 3) % 4]){
			dir = (dir + 3) % 4;
		}
		else if(!wall[x][y][dir]){
			if(wall[x][y][(dir + 1) % 4]){
				dir = (dir + 1) % 4;
			}
			else{
				dir = (dir + 2) % 4;
			}
		}
	} while(x != 0 || y != 0 || dir != 0);
	
	cout << s << endl;
}