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>

bool field[10][6];
int dir = 1;
int dx[] = { 0, 1, 0, -1 }, dy[] = { -1, 0, 1, 0 };
int x = 1, y = 0;
char s[5] = "URDL";

bool safe( int x, int y )
{
	return x >= 0 && x < 9 && y >= 0 && y < 9;
}

char g[9][9];

int main()
{
	for( int i = 0; i != 9; ++i )
	{
		std::string line;
		std::cin >> line;

		bool odd = i & 1;
		for( int j = !odd; j < 9; j += 2 )
		{
			g[i][j] = line[j/2] - '0' ? odd ? '|' : '_' : ' ';
			g[i][j+1] = '.';
		}

		if( !odd )
			g[i][0] = '.';
	}
	
	do
	{
		int fdir = ( 4 + dir - 1 ) % 4;
		int fx = x + dx[dir] + dx[fdir], fy = y + dy[dir] + dy[fdir];

		if( !safe( x, y ) || g[y][x] == ' ' )
		{
			x -= dx[dir], y -= dy[dir], dir = ( dir + 1 ) % 4;
			x += dx[dir], y += dy[dir];
		}
		else if( safe( fx, fy ) && ( g[fy][fx] == '_' || g[fy][fx] == '|' ) )
		{
			std::cout << s[dir];
			x += dx[dir], y += dy[dir], dir = ( 4 + dir - 1 ) % 4;
			x += dx[dir], y += dy[dir];
		}
		else
		{
			x += dx[dir] * 2, y += dy[dir] * 2;
			std::cout << s[dir];
		}

		if( x == 1 && y == 0 )
		{
			std::cout << s[dir];

			break;
		}
	}while( true );

	std::cout << std::endl;
	
	return 0;
}

C++: #include <string>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
typedef pair<int,int> P;
#define pb push_back
#define fi first
#define sec second
int angle=0;
int edge[6][6][4]={0};
vector<int> ans;
P now;
P nextpoint(P t,int angl)
{
	P f;
	f.fi=t.fi;
	f.sec=t.sec;
	if(angl==0)
	{
		f.sec++;
	}
	if(angl==1)
	{
		f.fi++;
	}
	if(angl==2)
	{
		f.sec--;
	}
	if(angl==3)
	{
		f.fi--;
	}
	return f;
}
void output(int n)
{
	if(n==0)
	{
		cout << 'R';
	}
	else if(n==1)
	{
		cout << 'D';
	}
	else if(n==2)
	{
		cout << 'L';
	}
	else
	{
		cout << 'U';
	}
	return ;
}
void step()
{
	int tmp;
	int ans;
	tmp=(angle+4-1)%4;
	while(1)
	{
		if(edge[now.fi][now.sec][tmp])break;
		tmp=(tmp+1)%4;
	}
	angle=tmp;
	P r;
	r.fi=nextpoint(now,angle).fi;
	r.sec=nextpoint(now,angle).sec;
	now.fi=r.fi;
	now.sec=r.sec;
	return ;
}
int main()
{
	now.fi=1;now.sec=1;
	for(int i=1;i<=9;i++)
	{
		if(i%2==1)
		{
			string s;
			cin >> s;
			for(int j=0;j<4;j++)
			{
				edge[(i+1)/2][j+1][0]=s[j]-'0';
				edge[(i+1)/2][j+2][2]=s[j]-'0';
			}
		}
		else
		{
			string s;
			cin >> s;
			for(int j=0;j<5;j++)
			{
				edge[i/2][j+1][1]=s[j]-'0';
				edge[i/2+1][j+1][3]=s[j]-'0';
			}
		}
	}
	while(1)
	{
		step();
		ans.pb(angle);
		if(now.fi==1&&now.sec==1)
		{
			break;
		}
	}
	for(int i=0;i<ans.size();i++)
	{
		output(ans[i]);
	}
	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 <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 + 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;
}