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>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

string wall[9];

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

inline int iswall(int cx,int cy,int d){
	switch(d){
		case 0:
			cy=2*cy;
			cx=cx-1;
			break;
		case 1:
			cy=2*cy-1;
			cx=cx;
			break;
		case 2:
			cy=2*cy-2;
			cx=cx-1;
			break;
		case 3:
			cy=2*cy-1;
			cx=cx-1;
			break;
	}
	if(cy<0||9<=cy||cx<0||5<=cx) return 0;

	return wall[cy][cx]=='1';
}

int main(void){
	rep(i,9){
		cin >> wall[i];
		if(wall[i].size()==4) wall[i]+="0";
	}
	int cx=1,cy=0,cd=1;
	map<int,char> dir;
	dir[0]='D',dir[1]='R',dir[2]='U',dir[3]='L';
	while(1){
		rep(i,4){
			int nd=(cd+i+3)%4;
			if(!iswall(cx,cy,nd)){
				if(i) cout << dir[nd];
				cy+=dy[nd],cx+=dx[nd],cd=nd;
				break;
			}
		}
		if(cx==1&&cy==0) break;
	}
	cout << endl;
	return 0;
}

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

char horz[5][4+1];
char vert[4][5+1];
int x, y, vx, vy;

void turn_left() {
	int temp = vx;
	vx = vy;
	vy = -temp;
}

void turn_right() {
	int temp = vx;
	vx = -vy;
	vy = temp;
}

inline bool ok(char c) { return (c == '1'); }

bool avail() {
	if (vx == 1) {
		if (x < 4 && ok(horz[y][x]))
			return true;
	} else if (vx == -1) {
		if (x > 0 && ok(horz[y][x-1]))
			return true;
	} else if (vy == 1) {
		if (y < 4 && ok(vert[y][x]))
			return true;
	} else /* if (vy == -1) */ {
		if (y > 0 && ok(vert[y-1][x]))
			return true;
	}
	return false;
}

void print() {
	if (vx == 1) cout << "R";
	else if (vx == -1) cout << "L";
	else if (vy == 1) cout << "D";
	else /* if (vy == -1) */ cout << "U";
}

int main() {
	for (int i = 0; i < 4; i++)
		cin >> horz[i] >> vert[i];
	cin >> horz[4];

	x=0, y=0, vx=0, vy=-1;
	do {
		while (!avail()) turn_right();
		print();
		x += vx, y += vy;
		turn_left();
	} while (x != 0 || y != 0);
	cout << endl;
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(void){
  int state; //ツ前ツ嘉アツづ個督ョツつ「ツつスツ陛サツ古シ
  int x, y; //current position
  bool horizon[5][4];
  bool vertical[4][5];
  char tmp;
  int i,j;

  for(i=0;i<9;i++){
	if(i%2 == 0){
	  for(j=0;j<4;j++){
		cin >> tmp;
		if(tmp == '1'){
		  horizon[i/2][j] = true;
		}else{
		  horizon[i/2][j] = false;
		}
	  }
	}else{
	  for(j=0;j<5;j++){
		cin >> tmp;
		if(tmp == '1'){
		  vertical[i/2][j] = true;
		}else{
		  vertical[i/2][j] = false;
		}
	  }
	}
  }

  state = 'R';
  cout << "R";
  x = 0;
  y = 1;
  
  while(!(x == 0 && y == 0)){
	if(state == 'R'){
	  if(x - 1 >= 0 && vertical[x-1][y] ){
		state = 'U';
		x--;
		cout << "U";
	  }else if(y <= 3 && horizon[x][y]){
		state = 'R';
		y++;
		cout << "R";
	  }else if(x <= 3 && vertical[x][y]){
		state = 'D';
		x++;
		cout << "D";
	  }else{
		state = 'L';
		y--;
		cout << "L";
	  }
	}else if(state == 'D'){
	  if(y <= 3 && horizon[x][y]){
		state = 'R';
		y++;
		cout << "R";
	  }else if(x <= 3 && vertical[x][y]){
		state = 'D';
		x++;
		cout << "D";
	  }else if( y >= 1 && horizon[x][y-1]){
		state = 'L';
		y--;
		cout << "L";
	  }else{
		state = 'U';
		x--;
		cout << "U";
	  }
	}else if(state == 'L'){
	  if(x <= 3 && vertical[x][y]){
		state = 'D';
		x++;
		cout << "D";
	  }else if(y >= 1 && horizon[x][y-1]){
		state = 'L';
		y--;
		cout << "L";
	  }else if(x >= 1 && vertical[x-1][y]){
		state = 'U';
		x--;
		cout << "U";
	  }else{
		state = 'R';
		y++;
		cout << "R";
	  }
	}else{
	  if(y >= 1 && horizon[x][y-1]){
		state = 'L';
		y--;
		cout << "L";
	  }else if(x >= 1 && vertical[x-1][y]){
		state = 'U';
		x--;
		cout << "U";
	  }else if(y <= 3 && horizon[x][y]){
		state = 'R';
		y++;
		cout << "R";
	  }else{
		state = 'D';
		x++;
		cout << "D";
	  }
	}
	//cout << x << " " << y << endl;
	//cin >> i;
  }
  cout << endl;
  return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
string ans="";
bool a[5][5][4] = {{{0}}};
int main(){
    string str;
    for(int i=0;i<9;i++){
        if(i%2==0){
            cin>>str;
            for(int j=0;j<4;j++){
                if(str[j]=='1'){

                    a[i/2][j][1] = true;
                    a[i/2][j+1][3] = true;
                    //cout<<"-("<<i/2<<" ,"<<j<<")("<<i/2<<" ,"<<j+1<<")"<<endl;
                }

            }
        }
        else{
            cin>>str;
            for(int j=0;j<5;j++){
                if(str[j]=='1'){
                    a[i/2][j][2] = true;
                    a[i/2+1][j][0] = true;
                    //cout<<"|("<<i/2<<" ,"<<j<<")("<<i/2+1<<" ,"<<j<<")"<<endl;
                }
				
            }
        }
    }
	cout<<"L";
		int x=1,y=0,way=1;
		while(1){
			if(x==0&&y==0)break;
			if(way == 0){
				if(x!=0&&a[y][x][3]){
					cout<<"L";
					x--;
					way = 3;
				}
				else if(y!=0&&a[y][x][0]){
					cout<<"U";
					y--;
					way = 0;
				}
				else if(x!=4&&a[y][x][1]){
					cout<<"R";
					x++;
					way = 1;
				}
				else if(y!=4&&a[y][x][2]){
					cout<<"D";
					y++;
					way = 2;
				}
			}
			else if(way == 1){
				if(y!=0&&a[y][x][0]){
					cout<<"U";
					y--;
					way = 0;
				}
				else if(x!=4&&a[y][x][1]){
					cout<<"R";
					x++;
					way = 1;
				}
				else if(y!=4&&a[y][x][2]){
					cout<<"D";
					y++;
					way = 2;
				}
				else if(x!=0&&a[y][x][3]){
					cout<<"L";
					x--;
					way = 3;
				}
			}
			else if(way == 2){
				if(x!=4&&a[y][x][1]){
					cout<<"R";
					x++;
					way = 1;
				}
				else if(y!=4&&a[y][x][2]){
					cout<<"D";
					y++;
					way = 2;
				}
				else if(x!=0&&a[y][x][3]){
					cout<<"L";
					x--;
					way = 3;
				}
				else if(y!=0&&a[y][x][0]){
					cout<<"U";
					y--;
					way = 0;
				}
			}
			else if(way == 3){
				if(y!=4&&a[y][x][2]){
					cout<<"D";
					y++;
					way = 2;
				}
				else if(x!=0&&a[y][x][3]){
					cout<<"L";
					x--;
					way = 3;
				}
				else if(y!=0&&a[y][x][0]){
					cout<<"U";
					y--;
					way = 0;
				}
				else if(x!=4&&a[y][x][1]){
					cout<<"R";
					x++;
					way = 1;
				}
			}
		}
    
	cout<<endl;
    return 0;
}