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 <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef vector <string> VS;
const int size = 9;

int main() {
    VS lines( size );
    for ( int i = 0; i < size; ++ i ) {
        cin >> lines[i];
    }

    bool O[size + 5][size + 5];
    for ( int i = 0; i < size + 5; ++ i ) {
        for ( int j = 0; j < size + 5; ++ j ) {
            O[i][j] = false;
        }
    }
    for ( int i = 0; i < size; ++ i ) {
        for ( int j = 0; j < ( i % 2 == 0 ? 4 : 5 ); ++ j ) {
            O[i+2][j+2] = ( lines[i][j] == '1' );
        }
    }

    const string T  = "RDLU";
    const int R = 0;
    const int D = 1;
    const int L = 2;
    const int U = 3;
    int r = 2;
    int c = 2;
    int s = R;

    while ( true ) {
        putchar( T[s] );
        if ( r == 2 && c == 2 && s == L ) break;
        if ( r == 3 && c == 2 && s == U ) break;

        if ( s == L ) {
            if ( O[r + 1][c] ) {
                ++ r;
                s = D;
            } else if ( O[r][c - 1] ) {
                -- c;
                s = L;
            } else if ( O[r - 1][c] ) {
                -- r;
                s = U;
            } else if ( O[r][c + 1] ) {
                ++ c;
                s = R;
            }
        } else if ( s == R ) {
            if ( O[r - 1][c + 1] ) {
                -- r;
                ++ c;
                s = U;
            } else if ( O[r][c + 1] ) {
                ++ c;
                s = R;
            } else if ( O[r + 1][c + 1] ) {
                ++ r;
                ++ c;
                s = D;
            } else if ( O[r][c - 1] ) {
                -- c;
                s = L;
            }
        } else if ( s == U ) {
            if ( O[r - 1][c - 1] ) {
                -- r;
                -- c;
                s = L;
            } else if ( O[r - 2][c] ) {
                r -= 2;
                s = U;
            } else if ( O[r - 1][c] ) {
                -- r;
                s = R;
            } else if ( O[r + 2][c] ) {
                r += 2;
                s = D;
            }
        } else if ( s == D ) {
            if ( O[r + 1][c] ) {
                ++ r;
                s = R;
            } else if ( O[r + 2][c] ) {
                r += 2;
                s = D;
            } else if ( O[r + 1][c - 1] ) {
                ++ r;
                -- c;
                s = L;
            } else if ( O[r - 2][c] ) {
                r -= 2;
                s = U;
            }
        }
    }
    putchar( '\n' );
    
    return 0;
}

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


using namespace std;

bool wall[11][11];

class Cbot{
private:

public:
	int x, y;
	int direc;
	string log;

	Cbot();
	int Start();

};

Cbot::Cbot(){
	x = 2;
	y = 0;
	direc = 1;
	log = "";
}

int Cbot::Start(){

	int rx[4] = { 1, 0, -1, 0 };
	int ry[4] = { 0, 1, 0, -1 };
	int fx[4] = { 0, 1, 0, -1 };
	int fy[4] = { -1, 0, 1, 0 };
	int dx[4] = { 0, 2, 0, -2 };
	int dy[4] = { -2, 0, 2, 0 };
	char logd[4] = { 'U', 'R', 'D', 'L' };

	int cnt = 0;

	while (1){

		//????????§??????
		if (wall[y + ry[direc]][x + rx[direc]] == 1){
			//????????§??????
			log += logd[direc];
			if (wall[y + fy[direc]][x + fx[direc]] == 0){
				//??????
				x += dx[direc];
				y += dy[direc];
			}
			else{
				//?????????
				if (direc == 0)direc = 3;
				else direc--;
			}
		}
		else{
			//?????????+??????
			if (direc == 3)direc = 0;
			else direc++;
			x += dx[direc];
			y += dy[direc];
		}

		//??´????????????
		if (x == 0 && y == 2 && direc == 3) break;
		if (x == 0 && y == 0 && direc == 0) break;
		if (cnt++ > 100) return 0;
	}

	return 1;
}

int main(){

	int index = 1;
	char buf;
	Cbot bot;

	for (int i = 0; i < 11; i++){
		for (int j = 0; j < 11; j++){
			wall[i][j] = 0;
		}
	}

	//??????????????????
	while (1){
		for (int i = 0; i < 4; i++){
			cin >> buf;
			wall[index][(i + 1) * 2] = buf - '0';
		}
		index++;
		if (index == 10)break;

		for (int i = 0; i < 5; i++){
			cin >> buf;
			wall[index][i * 2 + 1] = buf - '0';
		}
		index++;
	}

	bot.Start();

	cout << bot.log << endl;

	return 0;
}

C++: #include <iostream>
using namespace std;

int main(){
  int f,xyf;
  char h[5][4],v[4][5];
  int x,y;
  cin>>h[0];
  for(int i=0;i<4;i++){
    cin>>v[i];
    cin>>h[i+1];
  }
  f=xyf=1;
  y=0;
  x=1;cout<<"R";
  while(x!=0||y!=0){
    if(f==1){
      if(xyf==1){
	if(y>0&&v[y-1][x]=='1'){
	  y--;cout<<"U";f*=-1;xyf*=-1;
	}
	else if(x<4&&h[y][x]=='1'){
	  x++;cout<<"R";
	}
	else if(v[y][x]=='0'||y==4) xyf*=-1;
	else{
	  y++;f*=-1;cout<<"D";
	}
      }
      else{
	if(y>0&&v[y-1][x]=='1'){
	  y--;cout<<"U";f*=-1;
	}
	else if(x>0&&h[y][x-1]=='1'){
	  x--;cout<<"L";
	}
	else if(v[y][x]=='0'||y==4) xyf*=-1;
	else{
	  y++;cout<<"D";f*=-1;xyf*=-1;
	}
      }
    }
    else{
      if(xyf==1){
	if(x<4&&h[y][x]=='1'){
	  x++;cout<<"R";f*=-1;
	}
	else if(y<4&&v[y][x]=='1'){
	  y++;cout<<"D";
	}
	else if(h[y][x-1]=='0'||x==0) xyf*=-1;
	else{
	  x--;cout<<"L";f*=-1;xyf*=-1;
	}
      }
      else{
	if(x>0&&h[y][x-1]=='1'){
	  x--;cout<<"L";f*=-1;
	}
	else if(y>0&&v[y-1][x]=='1'){
	  y--;cout<<"U";
	}
	else if(h[y][x]=='0'||x==4) xyf*=-1;
	else{
	  x++;cout<<"R";f*=-1;xyf*=-1;
	}
      }
    }
  }
  cout.flush();
  cout<<endl;
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
 
using namespace std;
 
char d[10][6];
 
void solve(int y,int x,int way){
  if(y==0&&x==0){
    cout<<"L";
    return;
  }
  if(y==1&&x==0&&way==2){
    cout<<"U";
    return;
  }
  if(way==1){
    cout<<"R";
    if(y>0&&d[y-1][x+1]=='1')solve(y-1,x+1,2);
    else if(x<5&&d[y][x+1]=='1')solve(y,x+1,1);
    else if(y<8&&d[y+1][x+1]=='1')solve(y+1,x+1,4);
    else if(x>0&&d[y][x]=='1')solve(y,x,3);
  }
  else if(way==2){
    cout<<"U";
    if(x>0&&d[y-1][x-1]=='1')solve(y-1,x-1,3);
    else if(y>1&&d[y-2][x]=='1')solve(y-2,x,2);
    else if(x<4&&d[y-1][x]=='1')solve(y-1,x,1);
    else if(y<7&&d[y][x]=='1')solve(y,x,4);
  }
  else if(way==3){
    cout<<"L";
    if(y<8&&d[y+1][x]=='1')solve(y+1,x,4);
    else if(x>0&&d[y][x-1]=='1')solve(y,x-1,3);
    else if(y>0&&d[y-1][x]=='1')solve(y-1,x,2);
    else if(x<4&&d[y][x]=='1')solve(y,x,1);
  }
  else if(way==4){
    cout<<"D";
    if(x<4&&d[y+1][x]=='1')solve(y+1,x,1);
    else if(y<7&&d[y+2][x]=='1')solve(y+2,x,4);
    else if(x>0&&d[y+1][x-1]=='1')solve(y+1,x-1,3);
    else if(y>1&&d[y][x]=='1')solve(y,x,2);
  }
}
 
int main(void){
  for(int i=0;i<9;i++){
    cin>>d[i];
  }
  cout<<"R";
  solve(0,1,1);
  cout<<endl;
  return 0;
}