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>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
using namespace std;
typedef long long  ll;

/** Problem0037 : Path on a Grid **/
int main()
{
	string s, ds="LRUD";
	bool grid[5][5][4]={0};
	int y=0;
	rep(k, 9) {
		cin>>s;
		if (k%2==0) {
			for (int i=0; i<4; i++) {
				if (s[i] == '1') {
					grid[i][y][1]=true;
					grid[i+1][y][0]=true;
				}
			}
		} else {
			for (int i=0; i<5; i++) {
				if (s[i] == '1') {
					grid[i][y][3]=true;
					grid[i][y+1][2]=true;
				}
			}
			y++;
		}
	}
	int d=1, x=0; y=0;
	while (1) {
		switch (d) {
			case 1:
				if (grid[x][y][2]) {
					y--; d=2;
					cout << "U";
				} else if (grid[x][y][1]) {
					x++; d=1;
					cout << "R";
				} else if (grid[x][y][3]) {
					y++; d=3;
					cout << "D";
				} else {
					x--; d=0;
					cout << "L";
				} break;
				
			case 3:
				if (grid[x][y][1]) {
					x++; d=1;
					cout << "R";
				} else if (grid[x][y][3]) {
					y++; d=3;
					cout << "D";
				} else if (grid[x][y][0]) {
					x--; d=0;
					cout << "L";
				} else {
					y--; d=2;
					cout << "U";
				} break;
				
			case 0:
				if (grid[x][y][3]) {
					y++; d=3;
					cout << "D";
				} else if (grid[x][y][0]) {
					x--; d=0;
					cout << "L";
				} else if (grid[x][y][2]) {
					y--; d=2;
					cout << "U";
				} else {
					x++; d=1;
					cout << "R";
				} break;
				
			case 2:
				if (grid[x][y][0]) {
					x--; d=0;
					cout << "L";
				} else if (grid[x][y][2]) {
					y--; d=2;
					cout << "U";
				} else if (grid[x][y][1]) {
					x++; d=1;
					cout << "R";
				} else {
					y++; d=3;
					cout << "D";
				} break;
		}
		if (x==0 && y==0)
			break;
	}
	cout << endl;
	return 0;
}

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

string str[1000];
int len;
int fie[1001][1001];
int flag[1001][1001][4];
int m;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
char s[4]={'R','D','L','U'};
int main(void){
	int n=0;
	while(cin >> str[n])n++;
	m=str[0].size();
	for(int i=0;i<n;i++){
		for(int j=0;j<str[i].size();j++){
			if(str[i][j]=='1'){
				if(i%2==0)fie[j*2+2][i+1]=1;
				if(i%2==1)fie[j*2+1][i+1]=1;
			}
		}
	}
	int x=2,y=0,dir=0;
	while(1){
		int nx=x+dx[(dir+1)%4],ny=y+dy[(dir+1)%4];
		if(nx>=0 && nx<=m*2+2 && ny>=0 && ny<=n+1){
			if(fie[nx][ny]==1)printf("%c",s[dir]);
		}
		nx=x+dx[dir],ny=y+dy[dir];
		if(nx>=0 && nx<=m*2+2 && ny>=0 && ny<=n+1){
			if(fie[nx][ny]==0){
				x+=dx[dir]*2;
				y+=dy[dir]*2;
				if(fie[x+dx[(dir+1)%4]][y+dy[(dir+1)%4]]==0){
					dir=(dir+1)%4;
				}
			}else{
				if(fie[x+dx[(dir+3)%4]][y+dy[(dir+3)%4]]==0){
					dir=(dir+3)%4;
					x+=dx[dir]*2;
					y+=dy[dir]*2;
					printf("%c",s[dir]);
				}else{
					dir=(dir+2)%4;
					x+=dx[dir]*2;
					y+=dy[dir]*2;
					printf("%c",s[(dir+1)%4]);
					printf("%c",s[dir]);
				}
			}
		}
		//printf("%d %d %d %d %d\n",x,y,dir,dx[dir],dy[dir]);
		if(x==0 && y==0)break;
	}
	printf("\n");
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n) 
/*
const int dx[4] = {-1,0,0,0};
const int dy[4] = {0,-1,0,0};
const int dx2[4] = {-1,0,1,0};
const int dy2[4] = {0,1,0,-1};
*/
static const int dx[4] = {1,0,-1,0};
static const int dy[4] = {0,1,0,-1};
int main(void){
  int d = 0;
  /*
  int a[5][4];
  int b[4][5];
  */
  int m[9][9];
  int x=0,y=0;
  string tmp;
  /*
  for(int i=0; i<4; i++){
    for(int j=0; j<4; j++){
      c = getchar();
      a[i][j] = c - '0';
    }
    getchar();
    for(int j=0; j<5; j++){
      c = getchar();
      b[i][j] = c - '0';
    }
    getchar();
  }
  for(int j=0; j<4; j++){
    c = getchar();
    a[4][j] = c - '0';
  }
  */
  for(int i=0; i<9; i++){
    cin>>tmp;
    int jbegin;
    if(i%2){
      jbegin=0;
    }else{
      jbegin=1;
    }
    for(int j=jbegin,k=0; j<9; j+=2,k++){
      m[i][j] = tmp[k];
    }
  }
  for(int time=0; time>-1; time++){
    for(int r=-1; r<3; r++){
      //printf("%d",(d+r+4)%4);
      if(y+dy[(d+r+4)%4]>=0&&y+dy[(d+r+4)%4]<=8
          &&x+dx[(d+r+4)%4]>=0&&x+dx[(d+r+4)%4]<=8&&
          m[y+dy[(d+r+4)%4]][x+dx[(d+r+4)%4]]=='1'){
        d = (d+r+4)%4;
        x += 2*dx[d];
        y += 2*dy[d];
        break;
      }
    }
    char out;
    switch(d){
      case 0:
        out = 'R';
        break;
      case 1:
        out = 'D';
        break;
      case 2:
        out = 'L';
        break;
      case 3:
        out = 'U';
        break;
    }
    putchar(out);
    //printf("%d,%d\n",x,y);
    if(x==0&&y==0) break;
  }
  cout<<endl;
  return 0;
}

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

enum Dir
{
	U,R,D,L,DirSize
};

int main()
{
	bitset<DirSize+1> node[10][10];
	for(int y=0; y<5; y++)
	for(int x=0; x<5; x++)
	{
		node[y*2  ][x*2  ].set(R);
		node[y*2  ][x*2  ].set(D);
		node[y*2  ][x*2+1].set(D);
		node[y*2  ][x*2+1].set(L);
		node[y*2+1][x*2+1].set(L);
		node[y*2+1][x*2+1].set(U);
		node[y*2+1][x*2  ].set(U);
		node[y*2+1][x*2  ].set(R);
	}
	node[0][0].reset(D);
	node[1][0].reset(U);

	char str[16];
	for(int y=0; y<5; y++)
	{
		cin>>str;
		for(int x=0; x<4; x++)
		{
			if(str[x]=='1')
			{
				node[y*2  ][x*2+1].set(R);
				node[y*2  ][x*2+1].reset(D);
				node[y*2+1][x*2+1].set(R);
				node[y*2+1][x*2+1].reset(U);
				node[y*2  ][x*2+2].set(L);
				node[y*2  ][x*2+2].reset(D);
				node[y*2+1][x*2+2].set(L);
				node[y*2+1][x*2+2].reset(U);
			}
		}

		if(y==4) break;

		cin>>str;
		for(int x=0; x<5; x++)
		{
			if(str[x]=='1')
			{
				node[y*2+1][x*2  ].set(D);
				node[y*2+1][x*2  ].reset(R);
				node[y*2+1][x*2+1].set(D);
				node[y*2+1][x*2+1].reset(L);
				node[y*2+2][x*2  ].set(U);
				node[y*2+2][x*2  ].reset(R);
				node[y*2+2][x*2+1].set(U);
				node[y*2+2][x*2+1].reset(R);
			}
		}
	}

	int y=0,x=0;
	const int  dx[]={ 0, 1, 0,-1};
	const int  dy[]={-1, 0, 1, 0};
	const char dc[]={'U','R','D','L'};

	bool end=false;
	while(!end)
	{
		end=true;
		for(int i=0; i<4; i++)
		{
			if(node[y][x][i])
			{
				int nx=x+dx[i];
				int ny=y+dy[i];

				if(x/2!=nx/2 || y/2!=ny/2)
				{
					cout << dc[i];
				}
				x=nx; y=ny;
				node[y][x].reset((i+2)%4);
				end=false; break;
			}
		}	
	}
	cout << endl;
}