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;

int main(){
	int muki = 1;//0 is n,1 is e,2 is s,3 is w
	int t = 1, myoko= 1, mtate = 0;
	char yoko[7][6], tate[7][6];
	for(int i = 0; i < 7; i++){
		for(int j = 0; j < 6; j++){
			yoko[i][j] = '0';
			tate[i][j] = '0';
		}
	}
	for(int i = 1; i < 10; i++){
		if(i % 2 != 0){
			for(int j = 1; j < 5; j++){
				cin >> yoko[(i/2)+1][j];
			}
		}
		else{
			for(int j = 1; j < 6; j++){
				cin >> tate[j][t];
			}
			t++;
		}
	}
	cout << "R";
	while(myoko != 0 || mtate != 0){
		if(muki == 0){
			if(yoko[mtate+1][myoko] == '1'){
				myoko = myoko-1;
				cout << "L";
				muki = 3;
			}
			else if(tate[myoko+1][mtate] == '1'){
				mtate = mtate-1;
				cout << "U";
				muki = 0;
			}
			else if(yoko[mtate+1][myoko+1] == '1'){
				myoko = myoko+1;
				cout << "R";
				muki = 1;
			}
			else{
				mtate = mtate+1;
				cout << "D";
				muki = 2;
			}
		}
		else if(muki == 1){
			if(tate[myoko+1][mtate] == '1'){
				mtate = mtate-1;
				cout << "U";
				muki = 0;
			}
			else if(yoko[mtate+1][myoko+1] == '1'){
				myoko = myoko+1;
				cout << "R";
				muki = 1;
			}
			else if(tate[myoko+1][mtate+1] == '1'){
				mtate = mtate+1;
				cout << "D";
				muki = 2;
			}
			else{
				myoko = myoko-1;
				cout << "L";
				muki = 3;
			}
		}
		else if(muki == 2){
			if(yoko[mtate+1][myoko+1] == '1'){
				myoko = myoko+1;
				cout << "R";
				muki = 1;
			}
			else if(tate[myoko+1][mtate+1] == '1'){
				mtate = mtate+1;
				cout << "D";
				muki = 2;
			}
			else if(yoko[mtate+1][myoko] == '1'){
				myoko = myoko-1;
				cout << "L";
				muki = 3;
			}
			else{
				mtate = mtate-1;
				cout << "U";
				muki = 0;
			}
		}
		else{
			if(tate[myoko+1][mtate+1] == '1'){
				mtate = mtate+1;
				cout << "D";
				muki = 2;
			}
			else if(yoko[mtate+1][myoko] == '1'){
				myoko = myoko-1;
				cout << "L";
				muki = 3;
			}
			else if(tate[myoko+1][mtate] == '1'){
				mtate = mtate-1;
				cout << "U";
				muki = 0;
			}
			else{
				myoko = myoko+1;
				cout << "R";
				muki = 1;
			}
		}
	}
	cout << endl;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  vector<string>in(9);
  cout<<'R';
  rep(i,9)cin>>in[i];
  int x=1,y=0;
  int to=0;
  //int co=0;
  while(x||y){
    //co++;
    //if(co>50)break;
    //cout<<x<<" "<<y<<" "<<to<<endl;
    if(to==0){
      if(y!=0&&in[2*y-1][x]=='1'){
	y--;to=3;cout<<'U';
      }else if(x!=4&&in[2*y][x]=='1'){
	x++;cout<<'R';
      }else if(y!=4&&in[2*y+1][x]=='1'){
	y++;to=1;cout<<'D';
      }else if(x!=0&&in[2*y][x-1]=='1'){
	to=2;x--;cout<<'L';
      }
    }else if(to==1){
      if(x!=4&&in[2*y][x]=='1'){
	x++;to=0;cout<<'R';
      }else if(y!=4&&in[2*y+1][x]=='1'){
	y++;to=1;cout<<'D';
      }else if(x!=0&&in[2*y][x-1]=='1'){
	to=2;x--;cout<<'L';
      }else if(y!=0&&in[2*y-1][x]=='1'){
	y--;to=3;cout<<'U';
      }
    }else if(to==2){
      if(y!=4&&in[2*y+1][x]=='1'){
	y++;to=1;cout<<'D';
      }else if(x!=0&&in[2*y][x-1]=='1'){
	to=2;x--;cout<<'L';
      }else if(y!=0&&in[2*y-1][x]=='1'){
	y--;to=3;cout<<'U';
      }else if(x!=4&&in[2*y][x]=='1'){
	x++;to=0;cout<<'R';
      }
    }else if(to==3){
      if(x!=0&&in[2*y][x-1]=='1'){
	to=2;x--;cout<<'L';
      }else if(y!=0&&in[2*y-1][x]=='1'){
	y--;to=3;cout<<'U';
      }else if(x!=4&&in[2*y][x]=='1'){
	x++;to=0;cout<<'R';
      }else if(y!=4&&in[2*y+1][x]=='1'){
	y++;to=1;cout<<'D';
      }
    }
  }
  cout<<endl;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;


int main() {
	int g[100][100];
	memset(g, 0, sizeof(g));
	rep(i, 9) rep(j, 4 + i % 2) {
		char c;
		cin >> c;
		g[i + 1][j * 2 + (i + 1) % 2 + 1] = c - '0';
	}
	int dx[] = {0, 1, 0, -1};
	int dy[] = {-1, 0, 1, 0};
	char c[] = "URDL";
	int x = 2, y = 0, v = 1;
	do {
		cout << c[v];
		int pv = (v - 1 + 4) % 4;
		int nv = (v + 1) % 4;
		
		if (g[y + dy[v]][x + dx[v]] == 1) {
			v = pv;
		}
		else if (g[y + dy[v] * 2 + dy[nv]][x + dx[v] * 2 + dx[nv]] == 1) {
			x += dx[v] * 2;
			y += dy[v] * 2;
		}
		else {
			x += dx[v] * 2;
			x += dx[nv] * 2;
			y += dy[v] * 2;
			y += dy[nv] * 2;
			v = nv;
		}
		if (x == 0 && y == 0) break;
		if (x == 1 && y == 0) break;
	} while(true);
	cout << endl;
	
	return 0;
}