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<string> 
#include<vector>
#include<iostream>
using namespace std;
string vec="RULD";
bool map[20][20][4];
vector< string > maphor,mapver;
int xsize,ysize;
void init(){
	for(int i=0;i<xsize;i++){
		for(int j=0;j<ysize;j++){
			for(int k=0;k<4;k++){
				map[i][j][k]=0;
			}
		}
	}
}
void setmap(){
	for(int i=0;i<xsize;i++){
		for(int j=0;j<ysize;j++){
			if(-1<i&&i<ysize&&-1<j&&j<xsize){
				if(maphor[i][j]=='1'){
					map[i][j][0]=1;
				}
			}
			if(-1<i&&i<ysize&&-1<j-1&&j-1<xsize){
				if(maphor[i][j-1]=='1'){
					map[i][j][2]=1;
				}
			}
			if(-1<i&&i<ysize-1&&-1<j&&j<xsize){
				if(mapver[i][j]=='1'){
					map[i][j][3]=1;
				}
			}
			if(-1<i-1&&i-1<ysize-1&&-1<j&&j<xsize){
				if(mapver[i-1][j]=='1'){
					map[i][j][1]=1;
				}
			}
		}
	}
}

void solve(){
	int x=0,y=0;
	int v=0;
	int loop[4]={1,0,3,2};
	int vx[4]={1,0,-1,0};
	int vy[4]={0,-1,0,1};
	while(1){
		//cout<<x<<" "<<y<<endl;
		for(int i=0;i<4;i++){
			//cout<<vec[(v+loop[i])%4];
			if(x==0&&y==0&&(v+loop[i])%4==2){
				return;
			}
			if(map[y][x][(v+loop[i])%4]==1){
				v+=loop[i];
				v=v%4;
				x+=vx[v];
				y+=vy[v];
				//cout<<endl;
				cout<<vec[v];
				break;
			}
		}
	}
}

int main(){
	string tmp;
	for(int i=0;cin.eof()!=true;i++){
		cin>>tmp;
		if(i%2==0){
			maphor.push_back(tmp);
		}else{
			mapver.push_back(tmp);
		}
	}
	xsize=maphor[0].size()+1;
	ysize=mapver.size()+1;
	init();setmap();
	
	/*
	for(int i=0;i<xsize;i++){
		for(int j=0;j<ysize;j++){
			for(int k=0;k<4;k++){
				cout<<map[i][j][k];
			}
			cout<<" ";
		}
		cout<<endl;
	}*/
	solve();
	cout<<endl;
	
	return 0;
	
}

C++: #include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;
 
#define rep(i,n) for(int i=0;i<int(n);++i)
 
static const double PI=6*asin(0.5);
typedef complex<double> P;
typedef long long ll;

int m[10][10];
int p[10][10][10][10];
int vec=0;//right=0 down=1 left=2 up=3
int x=1,y=0;
int cou=0;

int pgo(int x,int y,int vec);

bool go_to(int x1,int y1,int x2,int y2){
	bool f;
    int a[]={x1,y1,x2,y2};
    rep(i,4){
        if(a[i]<0||a[i]>6) return false;
    }
    f= p[y1][x1][y2][x2]==1?true:false;
	if(f)
	//cout<<endl<<x1<<" "<<y1<<"  "<<x2<<" "<<y2<<endl;
	return f;
}
void dgo(int x,int y,int vec){
    cout<<"D";
	//cout<<"y="<<y<<endl;
	//vec=1;
	pgo(x,y+1,1);
}
void rgo(int x,int y,int vec){
    cout<<"R";
    //x++;
    //vec=0;
	pgo(x+1,y,0);
}
void lgo(int x,int y,int vec){
    cout<<"L";
    //x--;
    //vec=2;
	pgo(x-1,y,2);
}
void ugo(int x,int y,int vec){
    cout<<"U";
    //y--;
    //vec=3;
	pgo(x,y-1,3);
}

int pgo(int x,int y, int vec){
	cou++;
	//if(cou==30) return 0;
    if(x==1&&y==1&&cou!=1) return 0;
    else if(vec==0){
        if(go_to(x,y,x,y-1)) ugo(x,y,0);
        else if(go_to(x,y,x+1,y)) rgo(x,y,0);
        else if(go_to(x,y,x,y+1)) dgo(x,y,0);
        else if(go_to(x,y,x-1,y)) lgo(x,y,0);

    }
    else if(vec==1){
        if(go_to(x,y,x+1,y)) rgo(x,y,1);
        else if(go_to(x,y,x,y+1)) dgo(x,y,1);
        else if(go_to(x,y,x-1,y)) lgo(x,y,1);
        else if(go_to(x,y,x,y-1)) ugo(x,y,1);
    }
    else if(vec==2){
        if(go_to(x,y,x,y+1)) dgo(x,y,2);
        else if(go_to(x,y,x-1,y)) lgo(x,y,2);
        else if(go_to(x,y,x,y-1)) ugo(x,y,2);
        else if(go_to(x,y,x+1,y)) rgo(x,y,2);
    }
    else if(vec==3){
        if(go_to(x,y,x-1,y)) lgo(x,y,3);
        else if(go_to(x,y,x,y-1)) ugo(x,y,3);
        else if(go_to(x,y,x+1,y)) rgo(x,y,3);
        else if(go_to(x,y,x,y+1)) dgo(x,y,3);
    }
    //pgo(x,y,vec);
	return 0;
}

int main(){
    rep(a,10) rep(b,10) rep(c,10) rep(d,10) p[a][b][c][d]=0;
    rep(i,10) rep(j,10) m[i][j]=0;
    rep(i,4){
        char t;
    	string tm;
        int tmp;
        rep(j,4){
            cin>>t;
        	tm=t;
            if(tm=="0") tmp=0;
            else if(tm=="1") tmp=1;
        	//cout<<t<<" "<<tmp<<endl;
            p[i+1][j+1][i+1][j+2]=tmp;
            p[i+1][j+2][i+1][j+1]=tmp;
        		//cout<<tmp<<"  "<<j+1<<","<<i+1<<"-"<<j+2<<","<<i+1<<endl;
        }
        rep(j,5){
            cin>>t;
        	tm = t;
            if(tm=="0") tmp=0;
            else if(tm=="1") tmp=1;
            p[i+1][j+1][i+2][j+1]=tmp;
            p[i+2][j+1][i+1][j+1]=tmp;
        	
        		//cout<<tmp<<"  "<<j+1<<","<<i+1<<"-"<<j+2<<","<<i+1<<endl;
        }
    }
    rep(j,4){
        int i=4;
        char t;
        int tmp;
    	string tm;
        cin>>t;
    	tm = t;
        if(tm=="0") tmp=0;
        else if(tm=="1") tmp=1;
        p[i+1][j+1][i+1][j+2]=tmp;
        p[i+1][j+2][i+1][j+1]=tmp;
    	
        		//cout<<tmp<<"  "<<j+1<<","<<i+1<<"-"<<j+2<<","<<i+1<<endl;
    }
    
    pgo(1,1,0);
    cout<<endl;
    return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int field[6][6]={0};
  for(int i=0; i<9; i++){
    if(i%2 == 0){
      for(int j=0,a; j<4; j++){
	scanf("%1d",&a);
	field[i/2][j+1]+=4*a;
	field[i/2+1][j+1]+=a;
      }
    }
    else{
      for(int j=0,a; j<5; j++){
	scanf("%1d",&a);
	field[i/2+1][j]+=2*a;
	field[i/2+1][j+1]+=8*a;
      }
    }
  }
  int x=0,y=1,d=2;
  for(;;){
    if(d == 1){
      if(!(field[x][y]&2)){d = 2;y++;}
      else if(field[x][y]&1){cout <<"U";d = 8;}
      else{cout <<"U";x--;}
    }
    else if(d == 2){
      if(!(field[x][y]&4)){d = 4;x++;}
      else if(field[x][y]&2){cout <<"R";d = 1;}
      else{cout <<"R";y++;}
    }
    else if(d == 4){
      if(!(field[x][y]&8)){d = 8;y--;}
      else if(field[x][y]&4){cout <<"D";d = 2;}
      else{cout <<"D";x++;}
    }
    else if(d == 8){
      if(!(field[x][y]&1)){d = 1;x--;}
      else if(field[x][y]&8){cout <<"L";d = 4;}
      else{cout <<"L";y--;}
    }
    if(x == 0 && y == 1 && d == 2) break;
  }
  return 0;
}