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 <stdio.h>
#include<math.h>
#include <algorithm>
#include <stack>
using namespace std;
 
bool rangeCheck(int row, int col){
    if(row % 2 == 0){
        if(row >= 0 && row <= 8 && col >= 0 && col <= 3)return true;
        else{
            return false;
        }
    }else{
        if(row >= 0 && row <= 8 && col >= 0 && col <= 4)return true;
        else{
            return false;
        }
    }
}
 
int main(){
    int checkTable[9][5][4],row,col;
    char array[9][6];
 
    for(int i = 0; i < 9; i++){
        for(int k=0; k < 5; k++){
            for(int p=0;p<4;p++){
                checkTable[i][k][p] = 0;
            }
        }
    }
 
    for(int i=0;i < 9; i++){
        scanf("%s",array[i]);
    }
 
    printf("R");
    char current = 'R';
 
    checkTable[0][0][1] = 1;
 
    row = 0,col = 0;
 
    while(true){
        switch(current){
        case 'L':
            if(rangeCheck(row+1,col) == true &&checkTable[row+1][col][3] == 0 && array[row+1][col] == '1'){
                printf("D");
                checkTable[row+1][col][3] = 1;
                current = 'D';
                row = row+1;
            }else if(rangeCheck(row,col-1) == true &&checkTable[row][col-1][0] == 0 && array[row][col-1] == '1'){
                printf("L");
                checkTable[row][col-1][0] = 1;
                col = col-1;
            }else if(rangeCheck(row-1,col) == true &&checkTable[row-1][col][2] == 0 && array[row-1][col] == '1'){
                printf("U");
                checkTable[row-1][col][2] = 1;
                current = 'U';
                row = row-1;
            }else{
                printf("R");
                checkTable[row][col][1] = 1;
                current = 'R';
            }
            break;
        case 'R':
            if(rangeCheck(row-1,col+1) == true &&checkTable[row-1][col+1][2] == 0 && array[row-1][col+1] == '1'){
                printf("U");
                checkTable[row-1][col+1][2] = 1;
                current = 'U';
                row = row-1;
                col = col+1;
            }else if(rangeCheck(row,col+1) == true &&checkTable[row][col+1][1] == 0 && array[row][col+1] == '1'){
                printf("R");
                checkTable[row][col+1][1] = 1;
                col = col+1;
            }else if(rangeCheck(row+1,col+1) == true&&checkTable[row+1][col+1][3] == 0 && array[row+1][col+1] == '1'){
                printf("D");
                checkTable[row+1][col+1][3] = 1;
                current = 'D';
                row = row+1;
                col = col+1;
            }else{
                printf("L");
                checkTable[row][col][0] = 1;
                current = 'L';
            }
            break;
        case 'U':
            if(rangeCheck(row-1,col-1) == true &&checkTable[row-1][col-1][0] == 0 && array[row-1][col-1] == '1'){
                printf("L");
                checkTable[row-1][col-1][0] = 1;
                current = 'L';
                row = row-1;
                col = col-1;
            }else if(rangeCheck(row-2,col) == true&&checkTable[row-2][col][2] == 0 && array[row-2][col] == '1'){
                printf("U");
                checkTable[row-2][col][2] = 1;
                row = row - 2;
            }else if(rangeCheck(row-1,col)== true &&checkTable[row-1][col][1] == 0 && array[row-1][col] == '1'){
                printf("R");
                checkTable[row-1][col][1] = 1;
                current = 'R';
                row = row-1;
            }else{
               printf("D");
               checkTable[row][col][3] = 1;
               current = 'D';
            }
            break;
        case 'D':
            if(rangeCheck(row+1,col) == true&&checkTable[row+1][col][1] == 0 && array[row+1][col] == '1'){
                printf("R");
                checkTable[row+1][col][1] = 1;
                current = 'R';
                row = row+1;
            }else if(rangeCheck(row+2,col) == true&&checkTable[row+2][col][3] == 0 && array[row+2][col] == '1'){
                printf("D");
                checkTable[row+2][col][3] = 1;
                row = row+2;
            }else if(rangeCheck(row+1,col-1) == true&&checkTable[row+1][col-1][0] == 0 && array[row+1][col-1] == '1'){
                printf("L");
                checkTable[row+1][col-1][0] = 1;
                current = 'L';
                row = row +1;
                col = col -1;
            }else{
                printf("U");
                checkTable[row][col][2] = 1;
                current = 'U';
            }
            break;
        }
        if(row == 0 && col == 0)break;
    }
 
   printf("\n");
 
    return 0;
}

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

char w[10][8];

int dd[4][2] = {{0,1},{1,0},{0,-1},{-1,0}}, k;
char dr[8] = "RDLU";
int pos[2] = {0,1};

bool existWall(int i){
    int rem = (k+i+4)%4;
    if( pos[0] == 0 && rem == 3 ) return false;
    if( pos[1] == 0 && rem == 2 ) return false;
    if( rem%2 ){
        return w[2*pos[0]+2-rem][pos[1]] == '1';
    }else{
        return w[2*pos[0]][pos[1]-rem/2] == '1';
    }
}

int main(){
    for(int i = 0; i < 9; i++){
        cin >> w[i];
    }
    cout << 'R';
    k = 0;
    while( pos[0] != 0 || pos[1] != 0 ){
        for(int i = -1; i < 3; i++){
            if( existWall(i) ){
                k = (k+i+4)%4;
                break;
            }
        }
        pos[0] += dd[k][0];
        pos[1] += dd[k][1];
        cout << dr[k];
    }
    cout << endl;
    return 0;
}

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

string str[3000];
int len;
int fie[3001][3001];
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==2 || y==0))break;
	}
	printf("\n");
	return 0;
}