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 <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};

vector<pair<int, int>> G[55];

int main() {

  rep(i, 5) {
    char x;
    rep(j, 4) {
      cin >> x;
      if(x-'0') {
        G[i * 5 + j].emplace_back(i * 5 + j + 1, 2);
        G[i * 5 + j + 1].emplace_back(i * 5 + j, 0);
      }
    }

    if(i == 4) break;

    rep(j, 5) {
      cin >> x;
      if(x-'0') {
        G[i * 5 + j].emplace_back((i + 1) * 5 + j, 3);
        G[(i + 1) * 5 + j].emplace_back(i * 5 + j, 1);
      }
    }
  }

  string const OP = "LURD";

  int y = 0, x = 0, d = 2;

  while(y != 0 || x != 0 || d != 0) {
    int le = -1, st = -1, ri = -1;
    for(auto && e: G[y * 5 + x]) {
      if(e.second == (d + 3) % 4) le = e.second;
      if(e.second == (d + 1) % 4) ri = e.second;
      if(e.second == d) st = e.second;
    }
    if(le != -1) d = le;
    else if(st != -1) ;
    else if(ri != -1) d = ri;
    y += dy[d], x += dx[d];
    cout << OP[d];
  }
  cout << endl;
    
  return 0;
}

C++: #include<iostream>
#include<bitset>
#include<string>
#include<algorithm>
#define UP_DIRECTION 3
#define RIGHT_DIRECTION 2
#define DOWN_DIRECTION 1
#define LEFT_DIRECTION 0
using namespace std;
int dy[]={0,1,0,-1},dx[]={-1,0,1,0};
int main(){
    bitset<4>Square[5][5];
    string Wall[9];
    char For_Output[]="LDRU";
    for(int i=0;i<9;i++)cin>>Wall[i];

    for(int i=0;i<9;i+=2){
        Wall[i]="0"+Wall[i]+"0";
        for(int j=0;j<5;j++){
            Square[i/2][j][LEFT_DIRECTION]=(Wall[i][j]-'0');
            Square[i/2][j][RIGHT_DIRECTION]=(Wall[i][j+1]-'0');
        }
    }

    for(int i=1;i<9;i+=2){
        for(int j=0;j<5;j++){
            Square[i/2][j][DOWN_DIRECTION]=(Wall[i][j]-'0');
            Square[i/2+1][j][UP_DIRECTION]=(Wall[i][j]-'0');
        }
    }
    int Direction=RIGHT_DIRECTION;
    int y=0,x=0;

    do{
        int R=Direction-1;
        int L=Direction+1;
        int B=Direction-2;
        if(R<0)R=3;
        if(B<0)B+=4;
        L%=4;
        if(Square[y][x][L])
            Direction=L;

        else if(Square[y][x][Direction]);
        else if(Square[y][x][R])
            Direction=R;
        else Direction=B;

        y+=dy[Direction];
        x+=dx[Direction];
        cout<<For_Output[Direction];
    }while(y!=0||x!=0);
    cout<<endl;
}