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<bits/stdc++.h>
using namespace std;
string side[4],Longitudinal[5];
void righ(int x,int y);
void lef(int x,int y);
void up(int x,int y);
void down(int x,int y);
void serch(int x,int y,int then);
int main()
{
    for(int i=0;i<4;i++)cin>>Longitudinal[i]>>side[i];
    cin>>Longitudinal[4];
    cout<<"R";
    serch(1,0,0);
}
void righ(int x,int y)
{
    if(x+1<5&&Longitudinal[y][x]=='1'){
        cout<<"R";
        serch(x+1,y,0);
    }
}
void lef(int x,int y)
{
    if(x-1>-1){
        if(Longitudinal[y][x-1]=='1'){
            cout<<"L";
            serch(x-1,y,2);
        }
    }
}
void up(int x,int y)
{
    if(y-1>-1){
        if(side[y-1][x]=='1'){
            cout<<"U";
            serch(x,y-1,3);
        }
    }
}
void down(int x,int y)
{
    if(y+1<5&&side[y][x]=='1'){
            cout<<"D";
            serch(x,y+1,1);
        }
}
void serch(int x,int y,int then)
{
    if(x==0&&y==0){
        cout<<endl;
        exit(0);
    }
    if(then==0){
        up(x,y);
        righ(x,y);
        down(x,y);
        lef(x,y);
    }
    else if(then==1){
        righ(x,y);
        down(x,y);
        lef(x,y);
        up(x,y);
    }
    else if(then==2){
        down(x,y);
        lef(x,y);
        up(x,y);
        righ(x,y);
    }
    else{
        lef(x,y);
        up(x,y);
        righ(x,y);
        down(x,y);
    }
}

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


int main(){
	string str, ans = "";
	char h[7][6]= {0}; // setinel
	char v[6][7] = {0};
	char dir = 'n';
	int mx = 1;
	int my = 1;

	int i = 1;
	int j = 1;

	while(cin >> str){
		if(str.size() == 4){
			h[i][1] = str[0] - '0';
			h[i][2] = str[1] - '0';
			h[i][3] = str[2] - '0';
			h[i][4] = str[3] - '0';
			i++;
		}else if(str.size() == 5){
			v[j][1] = str[0] - '0';
			v[j][2] = str[1] - '0';
			v[j][3] = str[2] - '0';
			v[j][4] = str[3] - '0';
			v[j][5] = str[4] - '0';
			j++;
		}
	}
	
	do{
		if (v[my-1][mx] == 1 && dir != 'D' && (dir=='R' || h[my][mx-1] == 0)) {
			dir = 'U';
			my--;
		}else if (h[my][mx] == 1 && dir != 'L' && (dir=='D' || v[my-1][mx] == 0)) {
			dir = 'R';
			mx++;
		}else if (v[my][mx] == 1 && dir != 'U' && (dir=='L' || h[my][mx] == 0)) {
			dir = 'D';
			my++;
		}else if (h[my][mx-1] == 1 && dir != 'R' && (dir=='U' || v[my][mx] == 0)) {
			dir = 'L';
			mx--;
		}
		ans += dir;
	}while(!(mx == 1 && my == 1));

	cout << ans << endl;

	return 0;
}

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

bool map[11][11] = { false };
int x = 1, y = 1, vec = 0;
int dir[4] = {3, 0, 1, 2};
int dx[2][4] = { {1, 0, -1, 0}, {2, 0, -2, 0} };
int dy[2][4] = { {0, 1, 0, -1}, {0, 2, 0, -2} };
string opr[] = { "R", "D", "L", "U" };

void solve() {
	int tmp = 0;
	bool next = true;
	while (next) {
		for (int i = 0; i < 4; i++) {
			tmp = (dir[vec] + i) % 4;
			if (map[y + dy[0][tmp]][x + dx[0][tmp]]) {
				y += dy[1][tmp];
				x += dx[1][tmp];

				vec = tmp;
				cout << opr[tmp];
				if (x == 1 && y == 1) next = false;
				break;
			}
		}
	}
	cout << endl;
}

int main() {
	string str;
	int tmp;
	for (int i = 0; i < 9; i++) {
		cin >> str;
		if (i % 2 == 0) {
			for (int j = 0; j < 4; j++) {
				tmp = str[j] - '0';
				if (tmp == 1) {
					map[(i / 2) * 2 + 1][j * 2 + 1] = true;
					map[(i / 2) * 2 + 1][(j + 1) * 2] = true;
					map[(i / 2) * 2 + 1][(j + 1) * 2 + 1] = true;
				}
			}
		} else {
			for (int j = 0; j < 5; j++) {
				tmp = str[j] - '0';
				if (tmp == 1) {
					map[(i / 2 + 1) * 2][j * 2 + 1] = true;
					map[(i / 2 + 1) * 2 + 1][j * 2 + 1] = true;
				}
			}
		}
	}
	solve();

	return 0;
}

C++: hige

C++: #include<bits/stdc++.h>
using namespace std;
string side[4],Longitudinal[5];
void righ(int x,int y);
void lef(int x,int y);
void up(int x,int y);
void down(int x,int y);
void serch(int x,int y,int then);
int main()
{
    for(int i=0;i<4;i++)cin>>Longitudinal[i]>>side[i];
    cin>>Longitudinal[4];
    cout<<"R";
    serch(1,0,0);
}
void righ(int x,int y)
{
    if(x+1<5&&Longitudinal[y][x]=='1'){
        cout<<"R";
        serch(x+1,y,0);
    }
}
void lef(int x,int y)
{
    if(x-1>-1){
        if(Longitudinal[y][x-1]=='1'){
            cout<<"L";
            serch(x-1,y,2);
        }
    }
}
void up(int x,int y)
{
    if(y-1>-1){
        if(side[y-1][x]=='1'){
            cout<<"U";
            serch(x,y-1,3);
        }
    }
}
void down(int x,int y)
{
    if(y+1<5&&side[y][x]=='1'){
            cout<<"D";
            serch(x,y+1,1);
        }
}
int mox[2][4]={{0,1,0,-1},{0,0,0,-1}},moy[2][4]={{-1,0,1,0},{-1,0,0,0}};
char str[5]="URDL";
void serch(int x,int y,int then)
{
    if(then==-1)then=3;
    if(x==0&&y==0){
        cout<<endl;
        exit(0);
    }
    for(int i=0;i<4;i++){
        int now=(then+i)%4;
        if(now%2==0){
            if(y+moy[0][now]<5&&y+moy[0][now]>-1&&side[y+moy[1][now]][x]=='1'){
                cout<<str[now];
                serch(x,y+moy[0][now],now-1);
            }
        }
        else{
            if(x+mox[0][now]<5&&x+mox[0][now]>-1&&Longitudinal[y][x+mox[1][now]]=='1'){
                cout<<str[now];
                serch(x+mox[0][now],y,now-1);
            }
        }
    }
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int points[5][5];
int dir[4] = {1,2,4,8};
char dirc[4] = {'R','D','L','U'};
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
// [0,1,2,3] : [right,bottom,left,top]

int main(){
  REP(i,9){
    int x;
    cin>>x;
    if(i%2==0){
      // yokonaga
      REP(_j,4){
        int j = 3-_j;
        int val = x%10;
        x/=10;
        if(val==1){
          points[j][i/2] |= dir[0];
          points[j+1][i/2] |= dir[2];
        }
      }
    }else{
      // tatenaga
      REP(_j,5){
        int j = 4-_j;
        int val = x%10;
        x/=10;
        if(val==1){
          points[j][i/2] |= dir[1];
          points[j][i/2+1] |= dir[3];
        }
      }
    }
  }
  // input end
  int x=0, y=0, d=0;
  string res = "";
  while(!(x==0 && y==0) || res.size()==0){
    int kabe = (d+3)%4;
    if(points[x][y] & dir[kabe]) d = kabe;
    while(!(points[x][y] & dir[d])) d = (d+1)%4;
    res += dirc[d];
    x += dx[d];
    y += dy[d];
  }
  cout<<res<<endl;
  return 0;
}