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 (!(y - 2 < 0 || field[y-1][x] == '0')) {
                    dir = U;
                    y -= 2;
                    cout << DIRSTR[dir];
                    break;
                }
                if (x + 2 >= 9 || field[y][x+1] == '0')  {
                    if (!(y + 2 >= 9 || field[y+1][x] == '0')) {
                        dir = D;
                    } else {
                        dir = L;
                    }
                } else {
                    x += 2;
                    cout << DIRSTR[dir];
                }
                break;
            case D:
                if (!(x + 2 >= 9 || field[y][x+1] == '0'))  {
                    dir = R;
                    x += 2;
                    cout << DIRSTR[dir];
                    break;
                }
                if (y + 2 >= 9 || field[y+1][x] == '0') {
                    if (!(x - 2 < 0 || field[y][x-1] == '0')) {
                        dir = L;
                    } else {
                        dir = U;
                    }
                } else {
                    y += 2;
                    cout << DIRSTR[dir];
                }
                break;
            case L:
                if (!(y + 2 >= 9 || field[y+1][x] == '0')) {
                    dir = D;
                    y += 2;
                    cout << DIRSTR[dir];
                    break;
                }
                if (x - 2 < 0 || field[y][x-1] == '0') {
                    if (!(y - 2 < 0 || field[y-1][x] == '0')) {
                        dir = U;
                    } else {
                        dir = R;
                    }
                } else {
                    x -= 2;
                    cout << DIRSTR[dir];
                }
                break;
            case U:
                if (!(x - 2 < 0 || field[y][x-1] == '0')) {
                    dir = L;
                    x -= 2;
                    cout << DIRSTR[dir];
                    break;
                }
                if (y - 2 < 0 || field[y-1][x] == '0') {
                    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<cstdio>

int main(){
	char a[4][5];
	char b[5][4];
	int d = 2;
	int x = 0, y = 0;
	for(int i = 0; i < 4; i++){
		scanf("%c%c%c%c\n", &a[0][i], &a[1][i], &a[2][i], &a[3][i]);
		scanf("%c%c%c%c%c\n", &b[0][i], &b[1][i], &b[2][i], &b[3][i], &b[4][i]);
	}
	scanf("%c%c%c%c", &a[0][4], &a[1][4], &a[2][4], &a[3][4]);

	while(d){
		if(d == 2){
			if(y && b[x][y-1] - '0'){
				d = 1;
				y--;
				printf("U");
			}else if(x == 4){
				d = 3;
			}else if(a[x][y] - '0'){
				x++;
				printf("R");
			}else{
				d = 3;
			}
		}
		if(d == 3){
			if(x - 4 && a[x][y] - '0'){
				d = 2;
				x++;
				printf("R");
			}else if(y == 4){
				d = 4;
			}else if(b[x][y] - '0'){
				y++;
				printf("D");
			}else{
				d = 4;
			}
		}
		if(d == 4){
			if(y - 4 && b[x][y] - '0'){
				d = 3;
				y++;
				printf("D");
			}else if(x == 0){
				if(y == 0){
					printf("\n");
					return 0;
				}
				d = 1;
			}else if(a[x-1][y] - '0'){
				x--;
				printf("L");
			}else{
				d = 1;
			}
		}
		if(d == 1){
			if(x && a[x-1][y] - '0'){
				d = 4;
				x--;
				printf("L");
			}else if(y == 0){
				if(x == 0){
					printf("\n");
					return 0;
				}
				d = 2;
			}else if(b[x][y-1] - '0'){
				y--;
				printf("U");
			}else{
				d = 2;
			}
		}
	}
}

C++: #include <iostream>
#include <string>
using namespace std;
int main() {
	string in[9];
	int x = 0, y = 0, d = 0;
	//d..direction  0→、1↓、2←、3↑
	for (int i = 0; i < 9; i++)
		cin >> in[i];
	do {
		if (d == 0) {
			if (y > 0) {
				if (in[2 * y - 1][x] == '1') {
					cout << "U";
					d = 3;
					y--;
					continue;
				}
			}
			if (x < in[0].size()) {
				if (in[2 * y][x] == '1') {
					cout << "R";
					x++;
					continue;
				}
			}
			if (y < 4) {
				if (in[2 * y + 1][x] == '1') {
					cout << "D";
					d = 1;
					y++;
					continue;
				}
			}
			cout << "L";
			x--;
			d = 2;
			continue;
		}
		if (d == 1) {
			if (x < in[0].size()) {
				if (in[2 * y][x] == '1') {
					cout << "R";
					d = 0;
					x++;
					continue;
				}
			}
			if (y < 4) {
				if (in[2 * y + 1][x] == '1') {
					cout << "D";
					y++;
					continue;
				}
			}
			if (x > 0) {
				if (in[2 * y][x - 1] == '1') {
					cout << "L";
					d = 2;
					x--;
					continue;
				}
			}
			cout << "U";
			d = 3;
			y--;
			continue;
		}
		if (d == 2) {
			if (y < 4) {
				if (in[2 * y + 1][x] == '1') {
					cout << "D";
					d = 1;
					y++;
					continue;
				}
			}
			if (x > 0) {
				if (in[2 * y][x - 1] == '1') {
					cout << "L";
					x--;
					continue;
				}
			}
			if (y > 0) {
				if (in[2 * y - 1][x] == '1') {
					cout << "U";
					d = 3;
					y--;
					continue;
				}
			}
			cout << "R";
			d = 0;
			x++;
			continue;
		}
		if (d == 3) {
			if (x > 0) {
				if (in[2 * y][x - 1] == '1') {
					cout << "L";
					d = 2;
					x--;
					continue;
				}
			}
			if (y > 0) {
				if (in[2 * y - 1][x] == '1') {
					cout << "U";
					y--;
					continue;
				}
			}
			if (x < in[0].size()) {
				if (in[2 * y][x] == '1') {
					cout << "R";
					d = 0;
					x++;
					continue;
				}
			}
			cout << "D";
			d = 1;
			y++;
			continue;
		}
	}while (x != 0 || y != 0);
	cout << endl;
	return 0;
}