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>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
using namespace std;
#define M_PI 3.141592
#define toRad 2.0*M_PI/360.0
#define inin(x) int x;cin>>x;
#define all(x) x.begin(),x.end()

struct point
{
	bool b[4];
};



int main()
{
	point a[5][5];
	for (int i = 0; i < 5; i++)
	{
		for (int l = 0; l < 5; l++)
		{
			for (int k = 0; k < 4; k++)
			{
				a[i][l].b[k] = false;
			}
		}
	}

	for (int i = 0; i < 5; i++)
	{
		string str;
		cin >> str;
		for (int l = 0; l < 4; l++)
		{
			a[i][l].b[1] = a[i][l + 1].b[3] = str[l] - '0';
		}

		if (i != 5 - 1)
		{
			cin >> str;
			for (int l = 0; l < 5; l++)
			{
				a[i][l].b[2] = a[i + 1][l].b[0] = str[l] - '0';
			}
		}
	}
	int x, y, v;
	x = y = 0;
	v = 1;
	while (1)
	{
		int d[4] = { -1 + 4,0 + 4,+1 + 4,+2 + 4 };
		int dx[4] = { 0,1,0,-1 };
		int dy[4] = { -1,0,1,0 };
		char dc[5] = "URDL";
		for (int i = 0; i < 4; i++)
		{
			int di = (v + d[i]) % 4;
			if (a[y][x].b[di])
			{
				x += dx[di];
				y += dy[di];
				v = di;
				cout << dc[di];
				break;
			}
		}
		if (x == y&&x == 0)
		{
			cout << endl;
			return 0;
		}
	}



}

C++: #include <string>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
typedef pair<int,int> P;
#define pb push_back
#define fi first
#define sec second
int angle=0;
int edge[6][6][4]={0};
vector<int> ans;
P now;
P nextpoint(P t,int angl)
{
	P f;
	f.fi=t.fi;
	f.sec=t.sec;
	if(angl==0)
	{
		f.sec++;
	}
	if(angl==1)
	{
		f.fi++;
	}
	if(angl==2)
	{
		f.sec--;
	}
	if(angl==3)
	{
		f.fi--;
	}
	return f;
}
void output(int n)
{
	if(n==0)
	{
		cout << 'R';
	}
	else if(n==1)
	{
		cout << 'D';
	}
	else if(n==2)
	{
		cout << 'L';
	}
	else
	{
		cout << 'U';
	}
	return ;
}
void step()
{
	int tmp;
	int ans;
	tmp=(angle+4-1)%4;
	while(1)
	{
		if(edge[now.fi][now.sec][tmp])break;
		tmp=(tmp+1)%4;
	}
	angle=tmp;
	P r;
	r.fi=nextpoint(now,angle).fi;
	r.sec=nextpoint(now,angle).sec;
	now.fi=r.fi;
	now.sec=r.sec;
	return ;
}
int main()
{
	now.fi=1;now.sec=1;
	for(int i=1;i<=9;i++)
	{
		if(i%2==1)
		{
			string s;
			cin >> s;
			for(int j=0;j<4;j++)
			{
				edge[(i+1)/2][j+1][0]=s[j]-'0';
				edge[(i+1)/2][j+2][2]=s[j]-'0';
			}
		}
		else
		{
			string s;
			cin >> s;
			for(int j=0;j<5;j++)
			{
				edge[i/2][j+1][1]=s[j]-'0';
				edge[i/2+1][j+1][3]=s[j]-'0';
			}
		}
	}
	while(1)
	{
		step();
		ans.pb(angle);
		if(now.fi==1&&now.sec==1)
		{
			break;
		}
	}
	for(int i=0;i<ans.size();i++)
	{
		output(ans[i]);
	}
	cout << endl;
	return 0;
}

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

int main() {
  char c;
  bool a[10][5];
  bool b[5][5][4];
  char label[4] = {'R', 'D', 'L', 'U'};
  int dx[] = {0, 1, 0, -1};
  int dy[] = {1, 0, -1, 0}; 
  int x, y, d, nd;

  for (int i=0; i<9; i++) {
    int r = (i%2) ? 5 : 4;
    for (int j=0; j<r; j++) {
      cin >> c;
      a[i][j] = c - '0';
    }
  }

  for (int i=0; i<5; i++) {
    for (int j=0; j<5; j++) {
      b[i][j][0] = (j<4) ? a[2*i][j] : false;
      b[i][j][1] = (i<4) ? a[2*i+1][j] : false;
      b[i][j][2] = (j) ? a[2*i][j-1] : false;
      b[i][j][3] = (i) ? a[2*i-1][j] : false;
    }
  }

  d = 0;
  cout << label[d];
  x = 0; y = 1;
  do {
    for (int i=0; i<4; i++) {
      nd = (d+i+3)%4;
      if (b[x][y][nd]) {
        d = nd;
        break;
      }
    }
    cout << label[d];
    x += dx[d]; y+= dy[d];
  } while (x || y);
  cout << endl;

  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
#include <cassert>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

char m[10][10];

bool end(int x, int y) {
  return (x == 1 && y == 1) || (x == 0 && y == 1) ;
}

void check(int x, int y, int d) {
  printf("x,y = %d,%d : %d\n", x, y, d);
  assert(false);
}

int main() {
  memset(m, 0, sizeof m);
  string ans = "R";
  rep(i,9) scanf(" %s", m[i]);
  rep(i,9) {
    rep(j,5) {
      m[i][j] = (m[i][j] == '1') ? 1 : 0 ;
    }
  }
  // rep(i,9) {
  //   rep(j,5) printf("%2d", m[i][j]); puts("");
  // }

  int x = 1, y = 0, d = 1;
  do {
    // printf("(%d,%d) : %d : %s\n", x, y, d, ans.c_str());
    switch (d) {
      case 0: {
        // up
        if (m[2*(y-2)+1][x]) {
          // ok
          ans += 'U';
          --y;
        } else if (m[2*(y-1)][x]) {
          // ok
          ans += 'R';
          d = 1;
          ++x; --y;
        } else if (m[2*(y-1)][x-1]) {
          ans += 'L';
          d = 3;
        } else {check(x,y,d);}
        break;
      }
      case 1: {
        // right
        if (m[2*y][x]) {
          // ok
          ans += 'R';
          ++x;
        } else if (m[2*(y-1)+1][x]) {
          ans += 'U';
          d = 0;  
        } else if (m[2*y+1][x]) {
          // ok
          ans += 'D';
          d = 2;
          ++x; ++y;
        } else {check(x,y,d);}
        break;        
      }
      case 2: {
        // down
        if (m[2*y+1][x-1]) {
          // ok
          ans += 'D';
          ++y;
        } else if (m[2*y][x-1]) {
          ans += 'R';
          d = 1;
        } else if (m[2*y][x-2]) {
          // ok
          ans += 'L';
          d = 3;
          --x; ++y;
        } else {check(x,y,d);}
        break;
      }
      case 3: {
        // left
        if (m[2*(y-1)][x-2]) {
          // ok
          ans += 'L';
          --x;
        } else if (m[2*(y-2)+1][x-1]) {
          // ok
          ans += 'U';
          d = 0;
          --x; --y;
        } else if (m[2*(y-1)+1][x-1]) {
          ans += 'D';
          d = 2;
        } else {check(x,y,d);}
        break;        
      }
    }
  } while (!end(x,y) && ans.size() < 40);
  if (x == 1 && y == 1 && d == 0) ans += 'L';
  printf("%s\n", ans.c_str());
  return 0;
}