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<string>
using namespace std;
struct man{int x,y,d;};
int main(){
  string st[9];
  int i,j,k;
  for(i=0;i<9;i++) cin >> st[i];
  bool f=false;
  man m;
  m.x=0;m.y=0;m.d=0;
  int c=0;
  while(1){
    if(m.x==0&&m.y==0&&f) break;
    f=true;
    //cout << m.x<<":"<<m.y<<":"<<m.d << endl;
    if(m.d==0){
      if(st[m.y*2][m.x]=='1') {
	m.x++;
	cout << "R" ;
	//continue;
      }
      if(m.y>0){
	if(st[m.y*2-1][m.x]=='1') {
	  m.d=3;
	  continue;
	}
      }
      
      if(st[m.y*2+1][m.x]=='1') {
	m.d=1;
	continue;
      }
      //m.d=2;
      continue;
    }
    if(m.d==1){
      
      if(st[m.y*2+1][m.x]=='1') {
	m.y++;
	cout << "D" ;
	//continue;
      }
      if(m.x<4){
	if(st[m.y*2][m.x]=='1') {
	  m.d=0;
	  continue;
	}
      }
      if(st[m.y*2][m.x-1]=='1') {
	m.d=2;
	continue;
      }
      //m.d=3;
      continue;
    }
    if(m.d==2){
      
      if(st[m.y*2][m.x-1]=='1') {
	m.x--;
	cout << "L" ;
	//continue;
      }
      if(m.y<4){
	if(st[m.y*2+1][m.x]=='1') {
	  m.d=1;
	  continue;
	}
      }
      if(st[m.y*2-1][m.x]=='1') {
	m.d=1;
	continue;
      }
      //m.d=0;
      continue;
    }
    if(m.d==3){
      
      if(st[m.y*2-1][m.x]=='1') {
	m.y--;
	cout << "U" ;
	//continue;
      }
      if(m.x>0){
	if(st[m.y*2][m.x-1]=='1') {
	  m.d=2;
	  continue;
	}
      }
      if(st[m.y*2][m.x]=='1') {
	m.d=0;
	continue;
      }
      //m.d=1;
      continue;
    }
  }
  cout << endl;
  return 0;
}

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==1){
				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 <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;
}