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;

int map[12][12] = {0};
enum Dir{ RIGHT , DOWN , LEFT , UP };
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
char d[4] = { 'R' , 'D' , 'L' , 'U'};

int main(){
	int x = 2, y = 0, dir = RIGHT;
	string f;

	for(int y=0 ; y<9 ; y++){
		cin >> f;
		for(unsigned int x=0 ; x<f.size() ; x++){
			map[y+1][2*x+((y+1)%2)+1] = f[x] - '0';
		}
	}
	
	while( 1 ){
		if( x==0 && y==2 ) break;
		int mx = x + dx[dir];
		int my = y + dy[dir];
		int nx = x + dx[(dir+1)%4];
		int ny = y + dy[(dir+1)%4];
		if( map[ny][nx] == 1 ){
			cout << d[dir];
		}

		if( map[my][mx] == 0 ){		
			if( map[ny][nx] == 0 ){
				dir = (dir + 1) % 4;
				nx = x + dx[(dir+1)%4];
				ny = y + dy[(dir+1)%4];
				if( map[ny][nx] == 1 ){
					cout << d[dir];
				}
				x += dx[dir] * 2;
				y += dy[dir] * 2;
			}else{
				x += dx[dir] * 2;
				y += dy[dir] * 2;
			}
		}else{
			if( map[ny][nx] == 0 ){
				dir = ( dir + 1 ) % 4;
				nx = x + dx[(dir+1)%4];
				ny = y + dy[(dir+1)%4];
				if( map[ny][nx] == 1 ){
					cout << d[dir];
				}
				x += dx[dir] * 2;
				y += dy[dir] * 2;
			}else{
				dir = ( dir + 3 ) % 4;
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>

using namespace std;

char perm_angle[4] = {'R','U','L','D'};
int grid[5][5][4] = {0};

void move(int,int,char);
char det_angle(int,int,char);

int main(){
	int flag;
	for(int i=0;i<9;i++){
		if(i%2 == 0){
			for(int j=0;j<4;j++){
				fscanf(stdin,"%1d",&flag);
				//cout << flag;
				if(flag == 1){
					//cout << "+";
					grid[i/2][j][0]  = 1; //R
					grid[i/2][j+1][2]= 1; //L
				}
			}
		}
		else{
			for(int j=0;j<5;j++){
				fscanf(stdin,"%1d",&flag); 
				//cout << flag;
				if(flag == 1){
					//cout << "-";
					grid[i/2][j][3]  = 1; //D
					grid[i/2+1][j][1]= 1; //U
				}
			}
			
		}
		//cout << endl;
	}
	/*for(int i=0;i<5;i++){
		for(int j=0;j<5;j++){
			cout << 100*i+j;
			for(int k=0;k<4;k++){
				cout <<  " "  << grid[i][j][k];
			}
			cout << endl;
		}
	}*/
//	if(fscanf(stdin,"%1d",&map[i][j]) != EOF){

	//int x = 0, y = 0;
	//char angle = 'R';
	/*do{
		move(x,y,det_angle(x,y,angle))
	}while(x == 0 && y == 0);*/
	cout << 'R';
	move(0,1,'R');
}

void move(int x,int y,char angle){
	if(x == 0 && y== 0)
		exit(1);
	
	cout << angle;
	
	if(angle == 'R'){
		++y;
	}
	else if(angle == 'U'){
		--x;
	}
	else if(angle == 'L'){
		--y;
	}
	else if(angle == 'D'){
		++x;
	}
	//cout << "test" << x <<" " << y;
	move(x,y,det_angle(x,y,angle));
	//cout << angle << endl; 
}

char det_angle(int x,int y,char angle){
	
	//cout << x << y << " " << angle << endl;
	int start;
	if(angle == 'R'){
		start = 5;
	}
	else if(angle == 'U'){
		start = 6;
	}
	else if(angle == 'L'){
		start = 7;	
	}
	else if(angle == 'D'){
		start = 4;
	}
	//cout << start << endl;
	for(int i = start;start - i < 4 ;--i){
		if(grid[x][y][i%4] == 1){
			//cout << "kettei" << i <<endl ;
			return perm_angle[i%4];
		}
	}
	return 'Z';
}

C++: #include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
vector<string> strs;
int H,W;
bool isroad(int fx,int fy,int tx,int ty){
    int fromx,fromy,tox,toy;
    fromx=min(fx,tx);
    fromy=min(fy,ty);
    tox=max(fx,tx);
    toy=max(fy,ty);
    if(fromx<1 || tox<1 || tox>W || fromx>W || fromy<1 || toy<1 || fromy>H || toy>H) return false;
    if(fromx==tox){
        if(strs[(fromy-1)*2+1][fromx-1]=='1') return true;
        else{
            return false;
        }
    }else{
        if(strs[(fromy-1)*2][fromx-1]=='1') return true;
        else{
            return false;
        }
    }
}
int vx[]={1,0,-1,0},vy[]={0,-1,0,1};
int main(){
    string ins;
    while(cin>>ins){
        strs.push_back(ins);
    }
    W=strs[0].size()+1;
    H=strs.size()/2+1;
    int nx=2,ny=1,v=0;
    string outs="R";
    while(nx!=1 || ny!=1){
        for(int i=5;i>=3;i--){
            bool r=isroad(nx,ny,nx+vx[(v+i)%4],ny+vy[(v+i)%4]);
            if(r){
                v=(v+i)%4;
                nx+=vx[v];
                ny+=vy[v];
                if(v==0) outs+='R';
                else if(v==1) outs+='U';
                else if(v==2) outs+='L';
                else outs+='D';
                break;
            }
        }
    }
    cout<<outs<<endl;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <iostream>


using namespace std;



int main()
{
	bool points[5][5][4];
	for (int i = 0; i < 5; ++i)
		for (int j = 0; j < 5; ++j)
			for (int k = 0; k < 4; ++k)
				points[i][j][k] = false;

	for (int i = 0; i < 9; ++i)
	{
		int y = i/2;
		if (i%2 == 0)
		{
			for (int j = 0; j < 4; ++j)
			{
				int e;
				scanf("%1d", &e);
				if (e)
					points[y][j][1] = points[y][j+1][3] = true;
			}
		}
		else
		{
			for (int j = 0; j < 5; ++j)
			{
				int e;
				scanf("%1d", &e);
				if (e)
					points[y][j][2] = points[y+1][j][0] = true;
			}
		}
	}

	int x, y;
	x = 1;
	y = 0;
	int dir = 1;
	int dx[] = { 0, 1, 0, -1 };
	int dy[] = { -1, 0, 1, 0 };
	char* ds = "URDL";
	putchar(ds[dir]);
	while (!(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
			puts("owateru");

		x += dx[dir];
		y += dy[dir];
		putchar(ds[dir]);
	}

	return 0;
}

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