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;

struct point {
	int left;
	int down;
	int right;
	int up;
};

void move(point able[5][5], int& x, int& y, int& direction){
	switch(direction){
	case 0: 
		if(able[y][x].down){
			y++;
			direction = 3;
			cout << "D";
		}else if(able[y][x].left){
			x--;
			direction = 0;
			cout << "L";
		}else if(able[y][x].up){
			y--;
			direction = 1;
			cout << "U";
		}else if(able[y][x].right){
			x++;
			direction = 2;
			cout << "R";
		}
		break;
	case 1:
		if(able[y][x].left){
			x--;
			direction = 0;
			cout << "L";
		}else if(able[y][x].up){
			y--;
			direction = 1;
			cout << "U";
		}else if(able[y][x].right){
			x++;
			direction = 2;
			cout << "R";
		}else if(able[y][x].down){
			y++;
			direction = 3;
			cout << "D";
		}
		break;
	case 2:
		if(able[y][x].up){
			y--;
			direction = 1;
			cout << "U";
		}else if(able[y][x].right){
			x++;
			direction = 2;
			cout << "R";
		}else if(able[y][x].down){
			y++;
			direction = 3;
			cout << "D";
		}else if(able[y][x].left){
			x--;
			direction = 0;
			cout << "L";
		}
		break;
	case 3:
		if(able[y][x].right){
			x++;
			direction = 2;
			cout << "R";
		}else if(able[y][x].down){
			y++;
			direction = 3;
			cout << "D";
		}else if(able[y][x].left){
			x--;
			direction = 0;
			cout << "L";
		}else if(able[y][x].up){
			y--;
			direction = 1;
			cout << "U";
		}
	}
}

int main(){
	int direction = 3;
	int x = 0, y = 0;
	point able[5][5];
	char c;
	for(int i = 0; i < 5; i++)
		for(int j = 0; j < 5; j++){
			able[i][j].left = 0;
			able[i][j].right = 0;
			able[i][j].down = 0;
			able[i][j].up = 0;
		}
	for(int i = 0; i < 5; i++){
		for(int j = 0; j < 4; j++){
			cin >> c;
			if(c == '1'){
				able[i][j].right = 1;
				able[i][j+1].left = 1;
			}
		}
		if(i == 4) break;
		for(int j = 0; j < 5; j++){
			cin >> c;
			if(c == '1'){
				able[i][j].down = 1;
				able[i+1][j].up = 1;
			}
		}
	}
	move(able, x, y, direction);
	while(x != 0 || y != 0){
		move(able, x, y, direction);
	}
	cout << endl;
	return 0;
}

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

int main(){
	char WX[7][6],WY[6][7];
	for(int i=0;i<7;i++){
		for(int j=0;j<6;j++){
			WX[i][j] = 0;
			WY[j][i] = 0;
		}
	}
	for(int i=1;i<5;i++) cin >> WX[i][1];
	for(int i=1;i<6;i++) cin >> WY[1][i];
	for(int i=1;i<5;i++) cin >> WX[i][2];
	for(int i=1;i<6;i++) cin >> WY[2][i];
	for(int i=1;i<5;i++) cin >> WX[i][3];
	for(int i=1;i<6;i++) cin >> WY[3][i];
	for(int i=1;i<5;i++) cin >> WX[i][4];
	for(int i=1;i<6;i++) cin >> WY[4][i];
	for(int i=1;i<5;i++) cin >> WX[i][5];

	int NX = 1;
	int NY = 1;
	char s = 'R';
	while(1){
		if(s=='R'){
			if(WY[NY-1][NX]=='1'){ s = 'U'; NY--; cout << s;}
			else if(WX[NX][NY]=='1'){ NX++; cout << s;}
			else if(WY[NY][NX]=='1'){ s = 'D'; NY++; cout << s;}
			else s = 'L';
		}
		else if(s=='L'){
			if(WY[NY][NX]=='1'){ s = 'D'; NY++; cout << s;}
			else if(WX[NX-1][NY]=='1'){ NX--; cout << s;}
			else if(WY[NY-1][NX]=='1'){ s = 'U'; NY--; cout << s;}
			else s = 'R';
		}
		else if(s=='U'){
			if(WX[NX-1][NY]=='1'){ s = 'L'; NX--; cout << s;}
			else if(WY[NY-1][NX]=='1'){ NY--; cout << s;}
			else if(WX[NX][NY]=='1'){ s = 'R'; NX++; cout << s;}
			else s = 'D';
		}
		else if(s=='D'){
			if(WX[NX][NY]=='1'){ s = 'R'; NX++; cout << s;}
			else if(WY[NY][NX]=='1'){ NY++; cout << s;}
			else if(WX[NX-1][NY]=='1'){ s = 'L'; NX--; cout << s;}
			else s = 'U';
		}
		if(NX*NY==1) break;
	}
cout << endl;
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int H = 5;
const int W = 5;
const int D = 4;
const string DIR = "RULD";

int v[H][W][D], my[4] = {0, -1, 0, 1}, mx[4] = {1, 0, -1, 0}, d = 0, y = 0, x = 1;

int main() {
  REP(i, 9){
    string s; cin >>s;
    if(i % 2) REP(j, s.length()) if(s[j] == '1') v[(i + 1) / 2 - 1][j][3] = v[(i + 1) / 2][j][1] = true;
    if(!(i % 2)) REP(j, s.length()) if(s[j] == '1') v[i / 2][j][0] = v[i / 2][j + 1][2] = true;
  }
  stringstream ss; ss << 'R';
  while(y != 0 || x != 0){
    if(v[y][x][(d + 1) % 4]){
      d = (d + 1) % 4; y += my[d]; x += mx[d];
      ss << DIR[d];
    } else if (v[y][x][d]){
      y += my[d]; x += mx[d];
      ss << DIR[d];
    } else{
      d = (d + 3) % 4;
    }
  }
  cout <<ss.str() <<endl;
  return 0;
}