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>
using namespace std;

string line[9];

bool check( int x, int y ) {
    if ( y < 0 || y >= 9 ) return false;
    if ( y % 2 == 0 ) {
        if ( x < 0 || x >= 4 ) return false;
    } else {
        if ( x < 0 || x >= 5 ) return false;
    }
    return true;
}

int cnt;
void solve( int a, int x, int y ) {
    if ( cnt >= 2 ) return;

    if ( x == 0 && y == 0 ) {
        cnt++;
    }

    if ( y % 2 == 0 ) {
        cout << ( a ? "R" : "L" );
    } else {
        cout << ( a ? "U" : "D" );
    }

    if ( y % 2 == 0 ) {
        if ( a ) {
            if ( check(x+1,y-1) && line[y-1][x+1] == '1' ) {
                solve( 1, x+1, y-1 );
            } else if ( check(x+1,y) && line[y][x+1] == '1' ) {
                solve( 1, x+1, y );
            } else if ( check(x+1,y+1) && line[y+1][x+1] == '1' ) {
                solve( 0, x+1, y+1 );
            }
        } else {
            if ( check(x,y-1) && line[y-1][x] == '1' ) {
                solve( 1, x, y-1 );
            } else if ( check(x-1,y) && line[y][x-1] == '1' ) {
                solve( 0, x-1, y );
            } else if ( check(x,y+1) && line[y+1][x] == '1' ) {
                solve( 0, x, y+1 );
            }
        }
    } else {
        if ( a ) {
            if ( check(x-1, y-1) && line[y-1][x-1] == '1' ) {
                solve( 0, x-1, y-1 );
            } else if ( check(x, y-2) && line[y-2][x] == '1' ) {
                solve( 1, x, y-2 );
            } else if ( check(x, y-1) && line[y-1][x] == '1' ) {
                solve( 0, x, y-1 );
            }
        } else {
            if ( check(x, y+1) && line[y+1][x] == '1' ) {
                solve( 1, x, y+1 );
            } else if ( check(x, y+2) && line[y+2][x] == '1' ) {
                solve( 0, x, y+2 );
            } else if ( check(x-1, y+1) && line[y+1][x-1] == '1' ) {
                solve( 0, x-1, y+1 );
            }
        }
    }
}

int main() {
    for ( int i = 0; i < 9; i++ ) {
        cin >> line[i];
    }

    cnt = 0;
    solve( 1, 0, 0 );
    cout << endl;

    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>

using namespace std;

typedef enum _DIRECTION { dU, dR, dD, dL, DIR_MAX } DIR;

const int MAX_N = 5;
const int MAX_D = 4;

bool mat[MAX_N][MAX_N][MAX_D];

int main ( void )
{
	for (int i = 0; i < MAX_N; ++i) {
		for (int j = 0; j < MAX_N; ++j) {
			fill(mat[i][j], mat[i][j]+MAX_D, false);
		}
	}

	for (int i = 0; i < 9; ++i) {
		string str;
		cin >> str;

		if (i & 1) {
			for (int j = 0, J = str.size(); j < J; ++j) {
				mat[i/2][j][dD] = (str[j] == '1');
				if (i/2+1 < MAX_N) {
					mat[i/2+1][j][dU] = (str[j] == '1');
				}
			}
		}
		else {
			for (int j = 0, J = str.size(); j < J; ++j) {
				mat[i/2][j][dR] = mat[i/2][j+1][dL] = (str[j] == '1');
			}
		}
	}

	char c_dir[] = "URDL";
	int dx[] = { 0, 1, 0, -1 }, dy[] = { -1, 0, 1, 0 };
	DIR dir = dU;
	int x = 0, y = 0;
	bool hit = true;

	while (hit) {
		hit = false;
		for (int i = 0; i < DIR_MAX; ++i) {
			DIR next = (DIR)((dir + DIR_MAX - 1 + i) % DIR_MAX);
			if (mat[y][x][next]) {
				dir = next;
				mat[y][x][dir] = false;
				cout << c_dir[dir];
				x += dx[dir];
				y += dy[dir];
				hit = true;
				break;
			}
		}
	}
	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;
				}
			}
		}
		//	if(cin.eof())
	//		break;
		
		
// 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;
//						cout<<"U";
						str+='U';
					}
					// ºÉÇª êÎAºÖ
					else if(py!=4&&tate[py][px]=='1'){
						py++;
						angle=1;
//						cout<<"D";
						str+='D';
					}
					else{
						px--;
						angle=2;
						str+='L';
//						cout<<"L";
					}
				}
			}
			// º
			else if(angle==1){
				if(py!=4&&tate[py][px]=='1'){
//					cout<<"D";
					str+='D';
					py++;
				}
				else{
					// ºÉÇª³¯êÎA½]
					if(px!=4&&yoko[py][px]=='1'){
//						cout<<"R";
						str+='R';
						angle=0;
						px++;
					}
					else if(px!=0&&yoko[py][px-1]=='1'){
//						cout<<"L";
						str+='L';
						angle=2;
						px--;
					}
					else{
						py--;
						angle=3;
//						cout<<"U";
						str+='U';
					}
				}
			}
			// ¶
			else if(angle==2){
				if(px!=0&&yoko[py][px-1]=='1'){
//					cout<<"L";
					str+='L';
					px--;
				}
				else{
					// ºÉÇª êÎAºÖ
					if(py!=4&&tate[py][px]=='1'){
						py++;
						angle=1;
//						cout<<"D";
						str+='D';
					}
					// ãÖ
					else if(py!=0&&tate[py-1][px]=='1'){
						py--;
						angle=3;
//						cout<<"U";
						str+='U';
					}
					else{
						px++;
						angle=0;
//						cout<<"R";
						str+='R';
					}
				}
			}
			// ã
			else if(angle==3){
				if(py!=0&&tate[py-1][px]=='1'){
//					cout<<"U";
					str+='U';
					py--;
				}
				else{
					// ºÉÇª³¯êÎA½]
					if(px!=0&&yoko[py][px-1]=='1'){
//						cout<<"L";
						str+='L';
						angle=2;
						px--;
					}
					else if(px!=4&&yoko[py][px]=='1'){
//						cout<<"R";
						str+='R';
						angle=0;
						px++;
					}
					else{
						py++;
						angle=1;
//						cout<<"D";
						str+='D';
					}
				}
			}
			if(px==0&&py==0){
				break;
			}
}

cout<<str<<endl;
break;

}
return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
char dc[5] = "RDLU";
 
bool cangocw(int y, int x, int dir, vector<string> &s){
    if(dir%2==0){
        return s[2*y +1][x +1-(dir/2)] == '0';
    }else{
        return s[2*y +(1-dir/2)*2][x+1] == '0';
    }
}
 
int main(){
    vector<string> s(11);
    s[0] = s[10] = "0000000";
    for(int i=1; i<=9; i++){
        cin >> s[i];
        s[i] = "0" + s[i] + "0";
    }
    int dir=0;
    int x=0, y=0;
    string ans = "";
     
    do{
        if(cangocw(y, x, dir, s)){
            dir = (dir+1)%4;
            continue;
        }
        x += dx[dir];
        y += dy[dir];
        ans += dc[dir];
        dir = (dir+3)%4;
    }while(!(x==0 && y==0 && dir==0));
    cout << ans << endl;
    return 0;
}