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 <vector>
#include <algorithm>
#include <cstring>
#include <string>

using namespace std;

int main(){

	//while(1){
		char yoko[10][10];
		char tate[10][10];
		memset(yoko,0,sizeof(yoko));
		memset(tate,0,sizeof(tate));
		for(int i = 0; i < 5; i++){
			for(int j = 0; j < 4; j++){
				char c;
				cin>>c;
				yoko[i][j]=c;
			}
			if(i!=4){
				for(int j = 0; j < 5; j++){
					char c;
					cin>>c;
					tate[i][j]=c;
				}
			}
		}
		// 0,1,2,3ÅEAºA¶Aã
		int angle=0;
		int px,py;
		px=py=0;
		string str="";
		while(1){
			if(angle==0){
				if(px!=4&&yoko[py][px]=='1'){
					str+='R';
					px++;
				}
				else{
					// ãÖ
					if(py!=0&&tate[py-1][px]=='1'){
						py--;
						angle=3;
						str+='U';
					}
					// ºÉÇª êÎAºÖ
					else if(py!=4&&tate[py][px]=='1'){
						py++;
						angle=1;
						str+='D';
					}
					else{
						px--;
						angle=2;
						str+='L';
					}
				}
			}
			// º
			else if(angle==1){
				if(py!=4&&tate[py][px]=='1'){
					str+='D';
					py++;
				}
				else{
					// ºÉÇª³¯êÎA½]
					if(px!=4&&yoko[py][px]=='1'){
						str+='R';
						angle=0;
						px++;
					}
					else if(px!=0&&yoko[py][px-1]=='1'){
						str+='L';
						angle=2;
						px--;
					}
					else{
						py--;
						angle=3;
						str+='U';
					}
				}
			}
			// ¶
			else if(angle==2){
				if(px!=0&&yoko[py][px-1]=='1'){
					str+='L';
					px--;
				}
				else{
					// ºÉÇª êÎAºÖ
					if(py!=4&&tate[py][px]=='1'){
						py++;
						angle=1;
						str+='D';
					}
					// ãÖ
					else if(py!=0&&tate[py-1][px]=='1'){
						py--;
						angle=3;
						str+='U';
					}
					else{
						px++;
						angle=0;
						str+='R';
					}
				}
			}
			// ã
			else if(angle==3){
				if(py!=0&&tate[py-1][px]=='1'){
					str+='U';
					py--;
				}
				else{
					// ºÉÇª³¯êÎA½]
					if(px!=0&&yoko[py][px-1]=='1'){
						str+='L';
						angle=2;
						px--;
					}
					else if(px!=4&&yoko[py][px]=='1'){
						str+='R';
						angle=0;
						px++;
					}
					else{
						py++;
						angle=1;
						str+='D';
					}
				}
			}
			if(px==0&&py==0){
				break;
			}
}

cout<<str<<endl;
//break;

//}
return 0;
}

C++: #include<string> 
#include<vector>
#include<iostream>
using namespace std;
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<20;i++){
		for(int j=0;j<20;j++){
			if(-1<i&&i<maphor[0].size()&&-1<j&&j<maphor[0].size()){
				if(maphor[i][j]=='1'){
					map[i][j][0]=1;
				}
			}
			if(-1<i&&i<maphor.size()&&-1<j-1&&j-1<maphor[0].size()){
				if(maphor[i][j-1]=='1'){
					map[i][j][2]=1;
				}
			}
			if(-1<i&&i<mapver.size()&&-1<j&&j<mapver[0].size()){
				if(mapver[i][j]=='1'){
					map[i][j][3]=1;
				}
			}
			if(-1<i-1&&i-1<mapver.size()&&-1<j&&j<mapver[0].size()){
				if(mapver[i-1][j]=='1'){
					map[i][j][1]=1;
				}
			}
		}
	}
}

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

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;
	}
	if(solve()==-1)return -1;
	cout<<endl;
	
	return 0;
	
}

C++: #include<iostream>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const int N=6;
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};
const string op="RDLU";
enum{RIGHT=0,DOWN,LEFT,UP};
int m[N][N];
bool e[N][N][N];


string solve(){
  int y=0,x=1,r=RIGHT;
  string ret="";
  do{
    bool a=true;
    if (!e[y][x][(r+1)%4])r=(r+1)%4;
    while(e[y][x][r])ret+=op[r],r=(r+3)%4;
    if (e[y][x][(r+1)%4])ret+=op[r];
    y+=dy[r];
    x+=dx[r];
  }while(y != 0 || x != 1);
  return ret;
}

main(){
  rep(i,N)rep(j,N)rep(k,4)e[i][j][k]=false;
  rep(i,5){
    string tmp;
    cin>>tmp;
    rep(j,4)if (tmp[j] == '1')e[i][j+1][DOWN]=e[i+1][j+1][UP]=true;
    if (i == 4)break;
    cin>>tmp;
    rep(j,5)if (tmp[j] == '1')e[i+1][j][RIGHT]=e[i+1][j+1][LEFT]=true;
  }
  cout << solve() << endl;
}

C++: //0037
//include-------------------------------------
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<stack>

using namespace std;

//typedef--------------------------------------
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int, int> PII;

#define MP make_pair

//repetition-----------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

//constant-------------------------------------
const double PI = acos(-1.0);

//cout,cin-------------------------------------
#define COUT(x) cout<<(x)<<endl
#define CIN(x) cin>>(x)

int main(){
	int wall[5][5][4] = { { 0 }, { 0 }, { 0 } };
	int now[5][5];
	string dir = "RDLU";
	int dx[] = { 0, 1, 0, -1 };
	int dy[] = { 1, 0, -1, 0 };

	REP(i, 9){
		string st;
		CIN(st);
		if (i % 2) REP(j, 5){
			wall[(i - 1) / 2][j][1] = st[j]-'0';
			wall[(i - 1) / 2 + 1][j][3] = st[j] - '0';
		}
		else REP(j, 4){
			wall[i / 2][j][0] = st[j] - '0';
			wall[i / 2][j + 1][2] = st[j] - '0';
		}
	}

	int x = 0;
	int y = 1;
	now[x][y] = 0;
	
	cout << 'R';
	while (!(x == 0 && y == 0)){
		int p=now[x][y];
		if (wall[x][y][(now[x][y] + 3) % 4] == 1){
			x += dx[(now[x][y] + 3) % 4];
			y += dy[(now[x][y] + 3) % 4];
			now[x][y] = (p + 3) % 4;
			cout<< dir[now[x][y]];
		}
		else if (wall[x][y][now[x][y]] == 1){
			x += dx[now[x][y]];
			y += dy[now[x][y]];
			now[x][y] = p;
			cout<< dir[now[x][y]];
		}
		else{
			x += dx[(now[x][y] + 1) % 4];
			y += dy[(now[x][y] + 1) % 4];
			now[x][y] = (p + 1) % 4;
			cout<<dir[now[x][y]];
		}
	}

	cout << endl;

	return 0;
}