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>

using namespace std;

enum Direction {R, L, U, D};

bool input(char b[][5])
{
	char dummy;
	for (int i=0; i<9; i++) {
		for (int j=0; j<5; j++) {
			if ((i&1)==0 && j==4) continue;
			if ( !(cin >> b[i][j]) ) return false;
		}
		//cin >> dummy;
	}
	return true;
}

int main()
{
	char board[9][5];
	input(board);
	
	pair<int, int> curr_pos(0,0);
	enum Direction curr_dir = R;
	cout << "R";
	
	do {
		switch (curr_dir) {
		case R:
			// priority : U > R > D > L
			if ( curr_pos.first > 0 && board[curr_pos.first-1][curr_pos.second+1] == '1' ) {
				curr_dir = U; cout << "U"; curr_pos.first--; curr_pos.second++;
			} else if ( curr_pos.second < 3 && board[curr_pos.first][curr_pos.second+1] == '1' ){
				curr_dir = R; cout << "R"; curr_pos.second++;
			} else if ( curr_pos.first < 8 && board[curr_pos.first+1][curr_pos.second+1] == '1' ) {
				curr_dir = D; cout << "D"; curr_pos.first++; curr_pos.second++;
			} else {
				curr_dir = L; cout << "L";
			}
			break;
		case L:
			// priority : D > L > U > R
			if ( curr_pos.first < 8 && board[curr_pos.first+1][curr_pos.second] == '1' ) {
				curr_dir = D; cout << "D"; curr_pos.first++;
			} else if ( curr_pos.second > 0 && board[curr_pos.first][curr_pos.second-1] == '1' ) {
				curr_dir = L; cout << "L"; curr_pos.second--;
			} else if ( curr_pos.first > 0 && board[curr_pos.first-1][curr_pos.second] == '1' ) {
				curr_dir = U; cout << "U"; curr_pos.first--;
			} else {
				curr_dir = R; cout << "R";
			}
			break;
		case U:
			// priority : L > U > R > D
			if ( curr_pos.second > 0 && board[curr_pos.first-1][curr_pos.second-1] == '1' ) {
				curr_dir = L; cout << "L"; curr_pos.first--; curr_pos.second--;
			} else if ( curr_pos.first > 2 && board[curr_pos.first-2][curr_pos.second] == '1' ) {
				curr_dir = U; cout << "U"; curr_pos.first-=2;
			} else if ( curr_pos.second < 4 && board[curr_pos.first-1][curr_pos.second] == '1' ) {
				curr_dir = R; cout << "R"; curr_pos.first--;
			} else {
				curr_dir = D; cout << "D";
			}
			break;
		case D:
			// priority : R > D > L > U
			if ( curr_pos.second < 4 &&  board[curr_pos.first+1][curr_pos.second] == '1' ) {
				curr_dir = R; cout << "R"; curr_pos.first++;
			} else if ( curr_pos.first < 6 && board[curr_pos.first+2][curr_pos.second] == '1' ) {
				curr_dir = D; cout << "D"; curr_pos.first+=2;
			} else if ( curr_pos.second > 0 && board[curr_pos.first+1][curr_pos.second-1] == '1' ) {
				curr_dir = L; cout << "L"; curr_pos.first++; curr_pos.second--;
			} else {
				curr_dir = U; cout << "U";
			}
			break;
		}
	} while ( curr_pos.first != 0 || curr_pos.second != 0 );
	
	cout << endl;
	
	return 0;
}

C++: #include<stdio.h>
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
char*S="RDLU",c;
int main()
{
	int e[5][5][4]={};
	int i,j,x,y,a;
	for(i=0;i<9;++i)
	{
		if(i&1)
			for(j=0;j<5;++j)
				scanf(" %c",&c),e[i/2][j][1]=e[i/2+1][j][3]=c-'0';
		else
			for(j=0;j<4;++j)
				scanf(" %c",&c),e[i/2][j][0]=e[i/2][j+1][2]=c-'0';
	}
	for(x=y=a=0;;)
	{
		if(e[y][x][(a+3)%4])
		{
			a=(a+3)%4;
			putchar(S[a]);
			x+=dx[a];
			y+=dy[a];
		}
		else if(e[y][x][a])
		{
			putchar(S[a]);
			x+=dx[a];
			y+=dy[a];
		}
		else if(e[y][x][(a+1)%4])
		{
			a=(a+1)%4;
			putchar(S[a]);
			x+=dx[a];
			y+=dy[a];
		}
		else a=(a+2)%4;
		if(x+y+a==0)break;
	}
	puts("");
	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
using namespace std;
char walls[5][5][2];

int main()
{
	int x=0,y=0,flag=1;
	string tmp;
	for(int i = 0; i < 9; ++i)
	{
		flag=(flag+1)%2;
		cin>>tmp;
		for(int j = 0; j < 5; ++j)
		{
			if(!flag&&j==4) walls[i/2][4][flag]='0';
			else walls[i/2][j][flag]=tmp[j];
			//cin>>walls[i/2][j][flag];
		}
	}

	/*cout<<"debug"<<endl;	
	for(int i = 0; i < 5; ++i)
	{
		for(int j = 0; j < 5; ++j)
		{
			cout<<" "<<walls[i][j][0];
		}
		cout<<endl;
	}
	cout<<endl;
	for(int i = 0; i < 5; ++i)
	{
		for(int j = 0; j < 5; ++j)
		{
			cout<<" "<<walls[i][j][1];
		}
		cout<<endl;
	}*/
	//cout<<"end"<<endl;

	int dir=0;
	bool change=false;
	do {
		if(dir==0)
		{
			if(!change&&0<=y-1&&walls[y-1][x][1]=='1') 
			{
				dir=3;
				change=true;
			}
			else
			{
				if(x==4||walls[y][x][0]=='0')
				{
					dir=1;
					change=true;
				}
				else
				{
					++x;
					cout<<"R";
					change=false;
				}
			}
		}
		else if(dir==1)
		{
			if(!change&&x<4&&walls[y][x][0]=='1')
			{
				dir=0;
				change=true;
			}
			else
			{
				if(y==4||walls[y][x][1]=='0')
				{
					dir=2;
					change=true;
				}
				else
				{
					++y;
					cout<<"D";
					change=false;
				}
			}
		}
		else if(dir==2)
		{
			if(!change&&walls[y][x][1]=='1')
			{
				dir=1;
				change=true;
			}
			else
			{
				if(x==0||walls[y][x-1][0]=='0')
				{
					dir=3;
					change=true;
				}
				else
				{
					--x;
					cout<<"L";
					change=false;
				}
			}
		}
		else if(dir==3)
		{
			if(!change&&0<=x-1&&walls[y][x-1][0]=='1')
			{
				dir=2;
				change=true;
			}
			else
			{
				if(y==0||walls[y-1][x][1]=='0')
				{
					dir=0;
					change=true;
				}
				else
				{
					--y;
					cout<<"U";
					change=false;
				}
			}
		}
		//cout<<",x="<<x<<",y="<<y<<",dir="<<dir<<endl;
	} while(change||x!=0||y!=0);
	cout<<endl;
  return 0;
}

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

string yoko[5];
string tate[4];
int x = 0;
int y = 0;
char d;

void left()
{
	x--;
	d = 'L';
	cout << 'L';
}
void right()
{
	x++;
	d = 'R';
	cout << 'R';
}
void up()
{
	y--;
	d = 'U';
	cout << 'U';
}
void down()
{
	y++;
	d = 'D';
	cout << 'D';
}

int main()
{
	for (int i = 0; i < 9; i++)
	{
		if (i % 2 == 0) cin >> yoko[i / 2];
		else cin >> tate[i / 2];
	}

	right();

	while (true)
	{
		if (d == 'R')
		{
			if (y != 0 && tate[y - 1][x] == '1')  up();
			else if (x != 4 && yoko[y][x] == '1') right();
			else if (y != 4 && tate[y][x] == '1') down();
			else								  left();
		}
		else if (d == 'L')
		{
			if (y != 4 && tate[y][x] == '1')		  down();
			else if (x != 0 && yoko[y][x - 1] == '1') left();
			else if (y != 0 && tate[y - 1][x] == '1') up();
			else									  right();
		}
		else if (d == 'U')
		{
			if (x != 0 && yoko[y][x - 1] == '1')	  left();
			else if (y != 0 && tate[y - 1][x] == '1') up();
			else if (x != 4 && yoko[y][x] == '1')	  right();
			else									  down();
		}
		else if (d == 'D')
		{
			if (x != 4 && yoko[y][x] == '1')		  right();
			else if (y != 4 && tate[y][x] == '1')	  down();
			else if (x != 0 && yoko[y][x - 1] == '1') left();
			else									  up();
		}

		if (x == 0 && y == 0) break;
	}
	cout << endl;

	return 0;
}