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

vector<string> field;

void init() {
    string l;
    for (int i = 0; i < 9; i++) {
        cin >> l;
        string line = "";
        if (i % 2) {
            for (int j = 0; j < 9; j++) {
                if (j % 2) {
                    line.push_back(' ');
                } else {
                    line.push_back(l[j/2]);
                }
            }
        } else {
            for (int j = 0; j < 9; j++) {
                if (j % 2) {
                    line.push_back(l[j/2]);
                } else {
                    line.push_back(' ');
                }
            }
        }
        field.push_back(line);
    }
}

#define R 0
#define U 1
#define L 2
#define D 3

char DIRSTR[] = {'R', 'U', 'L', 'D'};

int main() {
    init();

    int dir = R;
    int x = 0;
    int y = 0;

    while (true) {
        switch (dir) {
            case R:
                if (x + 2 >= 9 || field[y][x+1] == '0')  {
                    if (!(y - 2 < 0 || field[y-1][x] == '0')) {
                        dir = U;
                    } else if (!(y + 2 >= 9 || field[y+1][x] == '0')) {
                        dir = D;
                    } else {
                        dir = L;
                    }
                } else {
                    x += 2;
                    cout << DIRSTR[dir];
                }
                break;
            case D:
                if (y + 2 >= 9 || field[y+1][x] == '0') {
                    if (!(x + 2 >= 9 || field[y][x+1] == '0'))  {
                        dir = R;
                    } else if (!(x - 2 < 0 || field[y][x-1] == '0')) {
                        dir = L;
                    } else {
                        dir = U;
                    }
                } else {
                    y += 2;
                    cout << DIRSTR[dir];
                }
                break;
            case L:
                if (x - 2 < 0 || field[y][x-1] == '0') {
                    if (!(y + 2 >= 9 || field[y+1][x] == '0')) {
                        dir = D;
                    } else if (!(y - 2 < 0 || field[y-1][x] == '0')) {
                        dir = U;
                    } else {
                        dir = R;
                    }
                } else {
                    x -= 2;
                    cout << DIRSTR[dir];
                }
                break;
            case U:
                if (y - 2 < 0 || field[y-1][x] == '0') {
                    if (!(x - 2 < 0 || field[y][x-1] == '0')) {
                        dir = L;
                    } else if (!(x + 2 >= 9 || field[y][x+1] == '0'))  {
                        dir = R;
                    } else {
                        dir = D;
                    }
                } else {
                    y -= 2;
                    cout << DIRSTR[dir];
                }
                break;
        }
        if (x == 0 && y == 0) break;
    }
    cout << endl;
    return 0;
}

C++: #include <stdio.h>
#include <string>

using namespace std;

int main(void) {
	int row, col;
	char direction = 'R';

	//char str[11][6] = { "00000","1111","00001","0110","01011","0010","01111","0010","01001","0111","00000" };
	char str[11][6] = {'\0'};
	for (int i = 1; i < 10; i++) {
		scanf("%s", str[i]);
	}

	printf("R");
	row = 1;
	col = 1;
	while (1) {
		switch (direction) {
		case 'U':
			//left
			if (col != 0 && str[row][col - 1] == '1') {
				direction = 'L';
				col = col - 1;
				printf("L");
			}
			//up
			else if (row != 1 && str[row - 1][col] == '1') {
				direction = 'U';
				row = row - 2;
				printf("U");
			}
			//right
			else if (col != 4 && str[row][col] == '1') {
				direction = 'R';
				col = col + 1;
				printf("R");
			}
			//down
			else if (row != 9 && str[row + 1][col] == '1') {
				direction = 'D';
				row = row + 2;
				printf("D");
			}
			break;
		case 'D':  
			//right
			if (col != 4 && str[row][col] == '1') {
				direction = 'R';
				col = col + 1;
				printf("R");
			}
			//down
			else if (row != 9 && str[row + 1][col] == '1') {
				direction = 'D';
				row = row + 2;
				printf("D");
			}
			//left
			else if (col != 0 && str[row][col - 1] == '1') {
				direction = 'L';
				col = col - 1;
				printf("L");
			}
			//up
			else if (row != 1 && str[row - 1][col] == '1') {
				direction = 'U';
				row = row - 2;
				printf("U");
			}
			break;
		case 'L':  
			//down
			if (row != 9 && str[row + 1][col] == '1') {
				direction = 'D';
				row = row + 2;
				printf("D");
			}
			//left
			else if (col != 0 && str[row][col - 1] == '1') {
				direction = 'L';
				col = col - 1;
				printf("L");
			}
			//up
			else if (row != 1 && str[row - 1][col] == '1') {
				direction = 'U';
				row = row - 2;
				printf("U");
			}
			//right
			else if (col != 4 && str[row][col] == '1') {
				direction = 'R';
				col = col + 1;
				printf("R");
			}
			break;
		case 'R':  
			//up
			if (row != 1 && str[row - 1][col] == '1') {
				direction = 'U';
				row = row - 2;
				printf("U");
			}
			//right
			else if (col != 4 && str[row][col] == '1') {
				direction = 'R';
				col = col + 1;
				printf("R");
			}
			//down
			else if (row != 9 && str[row + 1][col] == '1') {
				direction = 'D';
				row = row + 2;
				printf("D");
			}
			//left
			else if (col != 0 && str[row][col - 1] == '1') {
				direction = 'L';
				col = col - 1;
				printf("L");
			}
			break;
		}
		if (row == 1 && col == 1) {
			printf("L");
			break;
		}
	}

	printf("\n");

	return 0;
}