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 <cstring>
#include <cmath>
using namespace std;

int main()
{
    int p[5][5][4];
    for (int i = 0; i < 5; i++)
        for (int j = 0; j < 5; j++ )
            for (int k = 0; k < 4; k++) p[i][j][k] = 0;
    string s;
    for (int i = 0; i < 4; i++) {
        cin >> s;
        for (int j = 0; j < 4; j++) {
            if (s[j] == '1') {
                p[i][j][1] = p[i][j+1][3] = 1;
            }
        }
        cin >> s;
        for (int j = 0; j < 5; j++) {
            if (s[j] == '1') {
                p[i][j][2] = p[i+1][j][0] = 1;
            }
        }
    }
    cin >> s;
    for (int j = 0; j < 4; j++) {
        if (s[j] == '1') {
            p[4][j][1] = p[4][j+1][3] = 1;
        }
    }
    string DIR = "URDL";
    int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
    int px = 0, py = 1, dir = 1;
    cout << "R";
    int q = 0;
    while ((px != 0 || py != 0) && q++ < 40) {
        for (int i = 0; i < 4; i++) {
            if (p[px][py][(((dir + 3) % 4) + i) % 4] == 1) {
                dir = (((dir + 3) % 4) + i) % 4;
                px += dx[dir];
                py += dy[dir];
                cout << DIR[dir];
                break;
            }
        }
    }
    cout << endl;

    return 0;
}

C++: #include<stdio.h>///////AOJ0037
                            int
                            w[5
       ][5],i,j;char(b)[    128
       ],*           p;F    (//
       int           v){    for
       (i=    scanf("%s"    ,b)
       -1,    p=b    ;*p    ;++
       p){    w[p    -b+    1-v
       ][j    +v]|=((w[p    -b]
       [j]                  |=(
       p[0                  ]==
       49)<<3-v)&8>>v)>>2;}j+=v

     ;}
    main
  (){  for
 (;F     (0)
,j-       4;F
(1));for(p=b,
j=(       *b=
3)^       3;i        +=-66+"BAB\
C"[       *b]      ,j+=       "?\
@A"       "@"      [*b        ]-(
                   1<<        6),*
                   ++p        =(*
                   b)[        "U"
                   "L"        "D"
                   "R"        ],i
                    +j;)for((++*
  b)&=~4;!((1<<*
         b)&
         w[i
         ][j
]);      (*b
+=3      )&=
~4)     ;re\
turn   !puts
  (b+1);}

C++: #include <stdio.h>

char w[9][6];

bool is_up(int x, int y){
	if(y <= 0){ return false; }
	return w[y*2-1][x] == '1';
}

bool is_down(int x, int y){
	if(y >= 4){ return false; }
	return w[y*2+1][x] == '1';
}

bool is_left(int x, int y){
	if(x <= 0){ return false; }
	return w[y*2][x-1] == '1';
}

bool is_right(int x, int y){
	if(x >= 4){ return false; }
	return w[y*2][x] == '1';
}

int main(void){
	char r[100];
	int st = 0;
	int px=0, py=0;
	for(int i=0;i<9;++i){
		scanf("%s", w+i);
	}

	r[st++] = 'R';
	px=1;

	while(px!=0 || py!=0){
		switch(r[st-1]){
		case 'U':
			if(is_left(px, py)){ r[st++] = 'L'; px--; }
			else if(is_up(px, py)){ r[st++] = 'U'; py--; }
			else if(is_right(px, py)){ r[st++] = 'R'; px++; }
			else{ r[st++] = 'D'; py++; }
			break;
		case 'R':
			if(is_up(px, py)){ r[st++] = 'U'; py--; }
			else if(is_right(px, py)){ r[st++] = 'R'; px++; }
			else if(is_down(px, py)){ r[st++] = 'D'; py++; }
			else{ r[st++] = 'L'; px--; }
			break;
		case 'D':
			if(is_right(px, py)){ r[st++] = 'R'; px++; }
			else if(is_down(px, py)){ r[st++] = 'D'; py++; }
			else if(is_left(px, py)){ r[st++] = 'L'; px--; }
			else{ r[st++] = 'U'; py--; }
			break;
		case 'L':
			if(is_down(px, py)){ r[st++] = 'D'; py++; }
			else if(is_left(px, py)){ r[st++] = 'L'; px--; }
			else if(is_up(px, py)){ r[st++] = 'U'; py--; }
			else{ r[st++] = 'R'; px++; }
			break;
		default:
			puts("error");
			break;
		}
		//printf("%d,%d\n",px,py);
	}
	r[st] = '\0';
	puts(r);
	//getchar();getchar();
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
struct man{int x,y,d;};
int main(){
  string st[9];
  int i,j,k;
  for(i=0;i<9;i++) cin >> st[i];
  bool f=false,mo=false;
  man m;
  m.x=1;m.y=0;m.d=0;
  int c=0;
  cout << "R";
  while(c<50){
    c++;
    mo=false;
    
    if(m.x==1&&m.y==1&&m.d==2) {
      cout << "L";
      break;
    }
    if(m.x==0&&m.y==1&&f) {
      //cout << "U";
      break;
    }
    f=true;
    
    //cout << m.x<<":"<<m.y<<":"<<m.d << endl;
    if(m.d==0){
      if(m.y>0){
	if(st[m.y*2-1][m.x]=='1') {
	  cout << "R";
	  m.d=3;
	  continue;
	}
      }
      if(m.y<5){
	if(st[m.y*2][m.x]=='1') {
	  m.x++;
	  cout << "R";
	  continue;
	}
      }
      if(m.y<4){
	if(st[m.y*2+1][m.x]=='1') {
	  m.x++;
	  m.y++;
	  cout << "D";
	  m.d=1;
	  continue;
	}
      }
      m.y++;
      m.d=2;
      continue;
    }
    
    if(m.d==1){
      if(m.y<5){
	if(st[m.y*2][m.x-1]=='1') {
	  cout <<"D";
	  m.d=0;
	  continue;
	}
      }
      if(m.x>0&&m.y<4){
	if(st[m.y*2+1][m.x-1]=='1') {
	  m.y++;
	  cout << "D" ;
	  mo=true;
	  continue;
	}
      }
      if(m.x>1&&m.y<5){
	if(st[m.y*2][m.x-2]=='1') {
	  m.x--;
	  m.y++;
	  cout << "L";
	  m.d=2;
	  continue;
	}
      }
      m.x--;
      m.d=3;
      continue;
    }
    if(m.d==2){
      if(m.x>0){
	if(st[m.y*2-1][m.x-1]=='1') {
	  cout << "L";
	  m.d=1;
	  continue;
	}
      }
      if(m.x>1&&m.y>0){
	if(st[(m.y-1)*2][m.x-2]=='1') {
	  m.x--;
	  cout << "L" ;
	  mo=true;
	  continue;
	}
      }
      if(m.x>0&&m.y>1){
	if(st[(m.y-1)*2-1][m.x-1]=='1') {
	  m.x--;
	  m.y--;
	  cout << "U";
	  m.d=3;
	  continue;
	}
      }
      m.y--;
      m.d=0;
      continue;
    }
    if(m.d==3){

      if(m.y>0){
	if(st[(m.y-1)*2][m.x-1]=='1') {
	  cout << "U";
	  m.d=2;
	  continue;
	}
      }
      if(m.y>1){
	if(st[(m.y-1)*2-1][m.x]=='1') {
	  m.y--;
	  cout << "U" ;
	  mo=true;
	  continue;
	}
      }
      if(m.y>0){
	if(st[(m.y-1)*2][m.x]=='1') {
	  m.x++;
	  m.y--;
	  cout << "R";
	  m.d=0;
	  continue;
	}
      }
      m.x++;
      m.d=1;
      continue;
    }
    //if(!mo)m.d=(m.d+2)%4;
  }
  
  cout  << endl;
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
string side[4],Longitudinal[5];
int mox[2][2]={{1,-1},{0,-1}},moy[2][2]={{-1,1},{-1,0}};
char str[5]="URDL";
void serch(int x,int y,int then)
{
    if(then==-1)then=3;
    if(!x&&!y){
        cout<<endl;
        exit(0);
    }
    for(int i=0;i<4;i++){
        int now=(then+i)%4,ka=now/2;
        if(!(now%2)&&y+moy[0][ka]<5&&y+moy[0][ka]>-1&&side[y+moy[1][ka]][x]=='1'){
            cout<<str[now];
            serch(x,y+moy[0][ka],now-1);
        }
        else if(now%2&&x+mox[0][ka]<5&&x+mox[0][now/2]>-1&&Longitudinal[y][x+mox[1][ka]]=='1'){
            cout<<str[now];
            serch(x+mox[0][ka],y,now-1);
        }
    }
}
int main()
{
    for(int i=0;i<4;i++)cin>>Longitudinal[i]>>side[i];
    cin>>Longitudinal[4];
    cout<<"R";
    serch(1,0,0);
}