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);
    }
    else if(then==1){
        righ(x,y);
        down(x,y);
        lef(x,y);
    }
    else if(then==2){
        down(x,y);
        lef(x,y);
        up(x,y);
    }
    else{
        lef(x,y);
        up(x,y);
        righ(x,y);
    }
}

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

bool h[7][6]; // setinel
bool v[6][7];


int main(){
	string str, ans = "";
	char dir = 'n';
	int mx = 1;
	int my = 1;

	int i = 1;
	int j = 1;

	while(cin >> str){
		if(str.size() == 4){
			for (int k = 0; k < str.size(); k++) {
				h[i][k+1] = str[k] == '1' ? true : false;
			}
			i++;
		}else if(str.size() == 5){
			for (int k = 0; k < str.size(); k++) {
				v[j][k+1] = str[k] == '1' ? true : false;
			}
			j++;
		}
	}
	
	do{
		if (v[my-1][mx] && dir != 'D' && (dir=='R' || !h[my][mx-1])) {
			dir = 'U';
			my--;
		}else if (h[my][mx] && dir != 'L' && (dir=='D' || !v[my-1][mx])) {
			dir = 'R';
			mx++;
		}else if (v[my][mx] && dir != 'U' && (dir=='L' || !h[my][mx])) {
			dir = 'D';
			my++;
		}else if (h[my][mx-1] && dir != 'R' && (dir=='U' || !v[my][mx])) {
			dir = 'L';
			mx--;
		}
		ans += dir;
	}while(!(mx == 1 && my == 1));

	cout << ans << endl;

	return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a,T b){for(T i=a;i!=b;++i)cout<<*i<<" ";cout<<endl;}
template<class T> void chmin(T &t,T f){if(t>f)t=f;}
template<class T> void chmax(T &t,T f){if(t<f)t=f;}
int in(){int x;scanf("%d",&x);return x;}

int yoko[6][6],tate[6][6];

int state;
pint pos;


int main(){
	int i,j;
	for(i=0;i<4;i++){
		for(j=0;j<4;j++)yoko[i][j]=getchar()-'0';
		getchar();
		for(j=0;j<5;j++)tate[i][j]=getchar()-'0';
		getchar();
	}
	for(j=0;j<4;j++)yoko[4][j]=getchar()-'0';
	cout<<"R";
//cout<<endl;
	pos.first=1;
	pos.second=0;
	state=0;
/*	for(i=0;i<4;i++){
		for(j=0;j<4;j++)cout<<yoko[i][j];
		cout<<endl;
		for(j=0;j<5;j++)cout<<tate[i][j];
		cout<<endl;
	}
	for(j=0;j<4;j++)cout<<yoko[4][j];
	cout<<endl;
*/	
	
	while(pos.first!=0||pos.second!=0){
//cout<<pos.first<<" "<<pos.second<<endl;
		switch(state){
		case 0:
			if(pos.second!=0&&tate[pos.second-1][pos.first]==1){
				pos.second--;
				state=1;
			}else if(pos.first!=4&&yoko[pos.second][pos.first]==1){
				pos.first++;
				state=0;
			}else if(pos.second!=4&&tate[pos.second][pos.first]==1){
				pos.second++;
				state=3;
			}else{
				pos.first--;
				state=2;
			}
		break;
		case 1:
			if(pos.first!=0&&yoko[pos.second][pos.first-1]==1){
				pos.first--;
				state=2;	
			}else if(pos.second!=0&&tate[pos.second-1][pos.first]==1){
				pos.second--;
				state=1;
			}else if(pos.first!=4&&yoko[pos.second][pos.first]==1){
				pos.first++;
				state=0;
			}else{
				pos.second++;
				state=3;
			}
		break;
		case 2:
			if(pos.second!=4&&tate[pos.second][pos.first]==1){
				pos.second++;
				state=3;
			}else if(pos.first!=0&&yoko[pos.second][pos.first-1]==1){
				pos.first--;
				state=2;
			}else if(pos.second!=0&&tate[pos.second-1][pos.first]==1){
				pos.second--;
				state=1;
			}else{
				pos.first++;
				state=0;
			}
		break;
		case 3:
			if(pos.first!=4&&yoko[pos.second][pos.first]==1){
				pos.first++;
				state=0;
			}else if(pos.second!=4&&tate[pos.second][pos.first]==1){
				pos.second++;
				state=3;
			}else if(pos.first!=0&&yoko[pos.second][pos.first-1]==1){
				pos.first--;
				state=2;
			}else{
				pos.second--;
				state=1;
			}
		break;
		default: cout<<"hoge"<<endl;
		break;
		}
		if(state==0)cout<<"R";
		if(state==1)cout<<"U";
		if(state==2)cout<<"L";
		if(state==3)cout<<"D";
	}
	cout<<endl;


	return 0;
}

C++: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

bool is_path[10][10][10][10];
const char ch_dir[] = {'U','R','D','L'};

void dfs(int sx,int sy,int dir){
  for(int i=0;i<4;i++){
    int next_dir = (dir + i + 3) % 4;
    int dx = tx[next_dir] + sx;
    int dy = ty[next_dir] + sy;
    if(dx < 0 || dx > 4 || dy < 0 || dy > 4) continue;
    if(!is_path[sx][sy][dx][dy]) continue;

    printf("%c",ch_dir[next_dir]);
    if(dx == 0 && dy == 0) return;

    dfs(dx,dy,next_dir);
    break;
  }
}

int main(){

  memset(is_path,false,sizeof(is_path));
  for(int i=0;i<9;i++){
    char buf[8];
    scanf("%s",buf);
    int y = i / 2;
    
    if(i % 2 == 0){
      for(int x=0;x<4;x++){
	if(buf[x] == '1'){
	  is_path[x][y][x+1][y] = true;
	  is_path[x+1][y][x][y] = true;
	}
      }
    }
    else if(i % 2 != 0){
      for(int x=0;x<5;x++){
	if(buf[x] == '1'){
	  is_path[x][y][x][y+1] = true;
	  is_path[x][y+1][x][y] = true;
	}
      }
    }
  }

  dfs(0,0,1);
  printf("\n");
}