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 <vector>
using namespace std;

typedef vector <string> VS;

VS R;
string D = "RDLU";
const int RIGHT = 0;
const int DOWN = 1;
const int LEFT = 2;
const int UP = 3;

void dfs( int dir, int x, int y ) {
    cout << D[dir];

    if ( dir == RIGHT ) {
        if ( y-1 >= 0 && x+1 < R[y-1].size() && R[y-1][x+1] == '1' ) {
            return dfs( UP, x+1, y-1 );
        }
        if ( x+1 < R[y].size() && R[y][x+1] == '1' ) {
            return dfs( RIGHT, x+1, y );
        }
        if ( y+1 < R.size() && x+1 < R[y+1].size() && R[y+1][x+1] == '1' ) {
            return dfs( DOWN, x+1, y+1 );
        }
    } else if ( dir == DOWN ) {
        if ( y+1 < R.size() && x < R[y+1].size() && R[y+1][x] == '1' ) {
            return dfs( RIGHT, x, y+1 );
        }
        if ( y+2 < R.size() && R[y+2][x] == '1' ) {
            return dfs( DOWN, x, y+2 );
        }
        if ( y+1 < R.size() && x-1 >= 0 && R[y+1][x-1] == '1' ) {
            return dfs( LEFT, x-1, y+1 );
        }
    } else if ( dir == LEFT ) {
        if ( y+1 < R.size()&& x < R[y+1].size() && R[y+1][x] == '1' ) {
            return dfs( DOWN, x, y+1 );
        }
        if ( x-1 >= 0 && R[y][x-1] == '1' ) {
            return dfs( LEFT, x-1, y );
        }
        if ( y-1 >= 0 && x < R[y-1].size() && R[y-1][x] == '1' ) {
            return dfs( UP, x, y-1 );
        }
    } else if ( dir == UP ) {
        if ( y-1 >= 0 && x-1 >= 0 && R[y-1][x-1] == '1' ) {
            return dfs( LEFT, x-1, y-1 );
        }
        if ( y-2 >= 0 && R[y-2][x] == '1' ) {
            return dfs( UP, x, y-2 );
        }
        if ( y-1 >= 0 && x < R[y-1].size() && R[y-1][x] == '1' ) {
            return dfs( RIGHT, x, y-1 );
        }
    }
}

int main() {
    R = VS( 9 );
    for ( int i = 0; i < 9; i++ ) {
        cin >> R[i];
    }
    dfs( 0, 0, 0 );
    cout << endl;
    return 0;
}

C++: #include<cstdio>
using namespace std;
#define r(i,n) for(int i=0;i<n;++i)
int main()
{
	int f[5][5]={{0}};
	r(i,9){
		char s[6];
		scanf("%s",s);
		if(i%2){
			r(j,5){
				int a=s[j]-'0';
				f[i/2][j]|=a<<2;
				f[i/2+1][j]|=a;
			}
		}else{
			r(j,4){
				int a=s[j]-'0';
				f[i/2][j]|=a<<1;
				f[i/2][j+1]|=a<<3;
			}
		}
	}
	printf("R");
	int y=0,x=1,p=1;
	do{
		p=(p+2)%4;
		int d=p;
		do
			d=(d+1)%4;
		while(!((f[y][x]>>d)&1));
		p=d;
		putchar("URDL"[d]);
		int dx[] = {0, 1, 0, -1};
		int dy[] = {-1, 0, 1, 0};
		x+=dx[d];
		y+=dy[d];
	}while(y!=0||x!=0||f[0][0]==6&&p==3);
	puts("");
	return 0;
}

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

class Dot{
public:
  bool d[4];
  Dot() {
    d[0] = d[1] = d[2] = d[3] = false;
  }
};

int main() {
  Dot data[5][5];
  for(int i = 0; i < 9; i++) {
    string str;
    getline(cin, str);
    int y = i/2;
    if(i % 2 == 0) {
      for(int j = 0; j < 4; j++) {
	if(str[j] == '1') {
	  data[y][j].d[0] = data[y][j+1].d[2] = true;
	}
      }
    } else {
      for(int j = 0; j < 5; j++)  {
	if(str[j] == '1') {
	  data[y][j].d[1] = data[y+1][j].d[3] = true;
	}
      }
    }
  }

  int d[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
  int x = 0;
  int y = 0;
  int dir = 0;
  while(1) {
    for(int i = 0; i < 3; i++) {
      int t = (dir+i+3)%4;
      if(data[y][x].d[t]) {
	dir = t;
	x += d[t][0];
	y += d[t][1];
	switch(t) {
	case 0: cout << 'R'; break;
	case 1: cout << 'D'; break;
	case 2: cout << 'L'; break;
	case 3: cout << 'U'; break;
	}
	break;
      }
    }
    if(x == 0 && y == 0) {
      cout << endl;
      break;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;


int main(){

	while(1){
	char yoko[10][10];
	char tate[10][10];
	memset(yoko,0,sizeof(yoko));
	memset(tate,0,sizeof(tate));
	
	for(int i = 0; i < 5; i++){
		for(int j = 0; j < 4; j++){
			char c;
			cin>>c;
			yoko[i][j]=c;
		}
		if(i!=4){
			for(int j = 0; j < 5; j++){
				char c;
				cin>>c;
				tate[i][j]=c;
			}
		}
	}
	if(cin.eof())
		break;


	// 0,1,2,3ÅEAºA¶Aã
	int angle=0;
	int px,py;
	px=py=0;
	while(1){
		if(angle==0){
			if(px!=4&&yoko[py][px]=='1'){
				cout<<"R";
				px++;
			}
			else{
				// ãÖ
				if(py!=0&&tate[py-1][px]=='1'){
					py--;
					angle=3;
					cout<<"U";
				}
				// ºÉÇª êÎAºÖ
				else if(py!=4&&tate[py][px]=='1'){
					py++;
					angle=1;
					cout<<"D";
				}
				else{
					px--;
					angle=2;
					cout<<"L";
				}
			}
		}
		// º
		else if(angle==1){
			if(py!=4&&tate[py][px]=='1'){
				cout<<"D";
				py++;
			}
			else{
				// ºÉÇª³¯êÎA½]
				if(px!=4&&yoko[py][px]=='1'){
					cout<<"R";
					angle=0;
					px++;
				}
				else if(px!=0&&yoko[py][px-1]=='1'){
					cout<<"L";
					angle=2;
					px--;
				}
				else{
					py--;
					angle=3;
					cout<<"U";
				}
			}
		}
		// ¶
		else if(angle==2){
			if(px!=0&&yoko[py][px-1]=='1'){
				cout<<"L";
				px--;
			}
			else{
				// ºÉÇª êÎAºÖ
				if(py!=4&&tate[py][px]=='1'){
					py++;
					angle=1;
					cout<<"D";
				}
				// ãÖ
				else if(py!=0&&tate[py-1][px]=='1'){
					py--;
					angle=3;
					cout<<"U";
				}
				else{
					px++;
					angle=0;
					cout<<"R";
				}
			}
		}
		// ã
		else if(angle==3){
			if(py!=0&&tate[py-1][px]=='1'){
				cout<<"U";
				py--;
			}
			else{
				// ºÉÇª³¯êÎA½]
				if(px!=0&&yoko[py][px-1]=='1'){
					cout<<"L";
					angle=2;
					px--;
				}
				else if(px!=4&&yoko[py][px]=='1'){
					cout<<"R";
					angle=0;
					px++;
				}
				else{
					py++;
					angle=1;
					cout<<"D";
				}
			}
		}
		if(px==0&&py==0)
			break;
		}
		cout<<endl;

		}
		return 0;
}

C++: #include <stdio.h>
#include <string.h>
#define ROW_BLOCK 4
#define COL_BLOCK 4
#define ROW_NUM (ROW_BLOCK + 2) * 2 - 1
#define COL_NUM (COL_BLOCK + 2) * 2 - 1
#define UP 0
#define RIGHT 1
#define DOWN 2
#define LEFT 3

const char command[5] = "URDL";
const int dy[4] = {-1,0,1,0}, dx[4] = {0,1,0,-1};
const int gy = 1, gx = 1;

int main(void){
	int i, j, stage[ROW_NUM][COL_NUM];
	memset(stage,0,sizeof(stage));
	for(i = 1;i < ROW_NUM - 1;i++){
		char str[ROW_BLOCK + 2];
		scanf("%s",str);
		for(j = 1 + i % 2;j < COL_NUM - 1;j+=2){
			stage[i][j] = str[(j - 1) / 2] - '0';
		}
	}
	int nd = RIGHT, nx = 1, ny = 1;
	do{
		if(stage[ny + dy[nd]][nx + dx[nd]] == 0 && stage[ny + dy[(nd + 3) % 4]][nx + dx[(nd + 3) % 4]] == 0){ // 今向いている方向に壁がなく右手にも壁がなければれば
			nd = (nd + 1) % 4;
		}else if(stage[ny + dy[(nd + 3) % 4]][nx + dx[(nd + 3) % 4]] == 1){
			nd = (nd + 3) % 4;
			ny += dy[nd] * 2;
			nx += dx[nd] * 2;
			printf("%c",command[nd]);
		}else{
			ny += dy[nd] * 2;
			nx += dx[nd] * 2;
			printf("%c",command[nd]);
		}

		/*for(i = 0;i < ROW_NUM;i++){
			for(j = 0;j < COL_NUM;j++){
				if(ny == i && nx == j){
					printf("# ");
				}else{
					printf("%d ",stage[i][j]);
				}
			}
			printf("\n");
		}
		while(getchar() != '\n');*/
	}while(!((nx == gx) && (ny == gy)));
	printf("\n");
	return 0;
}