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>
char yokosen[7][6];
char tatesen[6][7];

int main(){
	for(int i=0;i<9;i++)scanf("%s",i%2?tatesen[i/2+1]+1:yokosen[i/2+1]+1);
	int dir=100000;
	int row=1;
	int col=2;
	printf("R");
	while(1){
	//	printf("\n%c %c",tatesen[row][col],yokosen[row][col]);
		switch(dir%4){
			case 0://migi
				if(tatesen[row-1][col]=='1'){
					dir--;
					row--;
					printf("U");
				}
				else if(yokosen[row][col]=='1'){
					col++;
					printf("R");
				}
				else if(tatesen[row][col]=='1'){
					row++;
					dir++;
					printf("D");
				}
				else {
					col--;
					dir+=2;
					printf("L");
				}
				break;
			case 1://shita
				if(yokosen[row][col]=='1'){
					col++;
					dir--;
					printf("R");
				}
				else if(tatesen[row][col]=='1'){
					row++;
					printf("D");
				}
				else if(yokosen[row][col-1]=='1'){
					col--;
					dir++;
					printf("L");
				}
				else{
					dir+=2;
					row--;
					printf("U");
				}
				break;
			case 2://hidari
				if(tatesen[row][col]=='1'){
					row++;
					dir--;
					printf("D");
				}
				else if(yokosen[row][col-1]=='1'){
					col--;
					printf("L");
				}
				else if(tatesen[row-1][col]=='1'){
					dir++;
					row--;
					printf("U");
				}
				else {
					col++;
					dir+=2;
					printf("R");
				}
				break;
			case 3://ue
				if(yokosen[row][col-1]=='1'){
					col--;
					dir--;
					printf("L");
				}
				else if(tatesen[row-1][col]=='1'){
					row--;
					printf("U");
				}
				else if(yokosen[row][col]=='1'){
					col++;
					dir++;
					printf("R");
				}
				else{
					dir+=2;
					row++;
					printf("D");
				}
				break;
		}
		if(row==1&&col==1)break;
	}
	printf("\n");
}

C++: #include <bits/stdc++.h>
using namespace std;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
const char ch[] = {"ULDR"};

bool g[10][10][10][10];

int main()
{
	char c;
	
	for (int i = 1; i <= 5; i++){
		for (int j = 1; j <= 4; j++){
			scanf(" %c", &c);
			if (c == '0') continue;
			g[i][j][i][j + 1] = true;
			g[i][j + 1][i][j] = true;
		}
		if (i == 5) continue;
		for (int j = 1; j <= 5; j++){
			scanf(" %c", &c);
			if (c == '0') continue;
			g[i][j][i + 1][j] = true;
			g[i + 1][j][i][j] = true;
		}
	}
	
	int dir = 3;
	int x = 1, y = 2;
	while (true){
		printf("%c", ch[dir]);
		if (x == 1 && y == 1) break;
		for (int t = 1; t >= -1; t--){
			int nd = (dir + t + 4) % 4;
			int nx = x + dx[nd];
			int ny = y + dy[nd];
			if (g[x][y][nx][ny]){
				x = nx;
				y = ny;
				dir = nd;
				break;
			}
		}
	}
	puts("");
	return 0;
}

C++: 
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int g[6][6][4]={};//top,bottom,left,right

int main(void) {
  int i,j;
  rep(i,9){
    string s;
    cin>>s;
    if(i%2){
      rep(j,5){
        g[i/2+1][j][3] = s[j] - '0';
        g[i/2+1][1+j][2] = g[i/2+1][j][3];
      }
    }else{
      rep(j,4){
        g[i/2+1][1+j][0] = s[j] - '0';
        g[i/2][1+j][1] = g[i/2+1][1+j][0];
      }
    }
  }

  char s[5] = {"LRDU"};
  int dx[4] = {0,0,1,-1};
  int dy[4] = {-1,1,0,0};

  int x=0,y=1,z=1;//(x,y)右手がz

  while(x+y){
    if(g[x][y][z]){
        cout<<s[z];
        if((z==1 && g[x][y][1] && g[x][y][3]) || (z==0 && g[x][y][0] && g[x][y][2]) ||
          (z==2 && g[x][y][2] && g[x][y][1]) || (z==3 && g[x][y][3] && g[x][y][0])){
            switch(z){
              case 0: z=2;break;
              case 1: z=3;break;
              case 2: z=1;break;
              case 3: z=0;break;
            }
        }else{
          x = x + dx[z];
          y = y + dy[z];
        }
    }else{
      switch(z){
        case 0: z=3;x--;break;
        case 1: z=2;x++;break;
        case 2: z=0;y--;break;
        case 3: z=1;y++;break;
      }
    }
  }
    cout<<endl;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    vector<vector<vector<bool> > > wall(6, vector<vector<bool> >(6, vector<bool>(4, false)));

    for(int i=0; i<5; ++i){
        for(int j=0; j<4; ++j){
            char a;
            cin >> a;
            if(a == '1')
                wall[i][j+1][1] = wall[i+1][j+1][3] = true;
        }
        if(i < 4){
            for(int j=0; j<5; ++j){
                char a;
                cin >> a;
                if(a == '1')
                    wall[i+1][j][0] = wall[i+1][j+1][2] = true;
            }
        }
    }

    char dir[] = {'R', 'D', 'L', 'U'};
    int dy[] = {0, 1, 0, -1};
    int dx[] = {1, 0, -1, 0};

    int y = 0;
    int x = 1;
    int d = 0;
    do{
        if(!wall[y][x][(d+1)%4]){
            ++ d;
            d %= 4;
        }
        if(!wall[y][x][d]){
            y += dy[d];
            x += dx[d];
            cout << dir[d];
        }else{
            d += 3;
            d %= 4;
        }
    }while(y != 1 || x != 0);

    cout << endl;
    return 0;
}