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>
using namespace std;

int a[12][12];
int dx[4]  = {1,0,-1,0};
int dy[4]  = {0,1,0,-1};
char dc[4] = {'R','D','L','U'};
string f[4] = {"¨" , "«" , "©", "ª"};

//©ªÌüÍS}XÌÇÌóÔð²×é
void cheakWall(int* wall , const int& px ,const int& py ,const int& d ){
	for(int i=0 ; i<4 ; ++i ){
		int mx = px + dx[(d+i)%4];
		int my = py + dy[(d+i)%4];
		wall[i] = a[my][mx];
	}
}

//iÞ
void go(int& px, int& py, const int& d,int* wall, string& s){
	px += dx[d]*2;
	py += dy[d]*2;
	//cheakWall( wall , px , py , d );
	if( wall[1] ){
		//iñ¾ü«ðL^
		s.push_back( dc[d] );
	}
}

int main(){
	string s;

	//zñÌú»
	for(int y=0 ; y<12 ; ++y )
		for(int x=0 ; x<12 ; ++x )
			a[y][x] = 0;

	//üÍ
	for(int i=0 ; i<9 ; ++i ){
		cin >> s;
		int y = i+1;
		int x = (i+1)%2 + 1;
		for(int j=0 ; j<(int)s.size() ; ++j , x+=2 ){
			a[y][x] = s[j] - '0';
		}
	}

	int px = 2, py = 0, d = 0;
	bool flag = false;
	s.clear();

	while( 1 ){
		//cout << "x:" << px << " y:" << py << " d:" << f[d] << endl;
		if( px == 0 && py == 0 ) break;

		int wall[4]; 
		//©ªÌüèÌóÔ
		cheakWall( wall , px , py , d );

		if( !wall[1] ){//EªÇ¶áÈ©Á½ç
			//ü«ðEü«Éñé
			d = (d+1)%4;
			//iÞ
			go( px , py , d , wall , s );
			flag = false;
		}else{
			if( !wall[0] ){//OªÇ¶áÈ©Á½ç
				//iÞ
				go( px , py , d , wall , s );
				flag = false;
			}else{
				if( !wall[3] ){//¶ªÇ¶áÈ©Á½ç
					if( wall[1] && flag == false ){
						//iñ¾ü«ðL^
						s.push_back( dc[d] );
					}
					//ü«ð¶ü«Éñé
					d = (d+3)%4;
					//iÞ
					go( px , py , d , wall , s );
					flag = false;
				}else{//OEEE¶ªÇ¾Á½ç
					flag = true;
					if( wall[1] ){
						//iñ¾ü«ðL^
						s.push_back( dc[d] );
					}
					//ü«ðEü«Éñé
					d = (d+3)%4;
					//iñ¾ü«ðL^
					s.push_back( dc[d] );
				}
			}
		}
	}
	cout << s << endl;
}

C++: #include <stdio.h>

void change(int,int);
int wall_x[4][5],wall_y[5][4],muki = 0,flag = 0;

int main(){
	int i,j,x = 0,y = 0;
	for(i = 0;i < 9;i++){
		if(i % 2 == 0) for(j = 0;j < 4;j++) scanf("%1d",&wall_x[j][i / 2]);
		else for(j = 0;j < 5;j++) scanf("%1d",&wall_y[j][(i - 1)/ 2]);
	}
	do{
		if(muki == 0){
			if(x != 4 && wall_x[x][y] == 1){
				flag = 0;
				printf("R");
				x++;
			}else change(x,y);
		}else if(muki == 1){
			if(y != 4 && wall_y[x][y] == 1){
				flag = 0;
				printf("D");
				y++;
			}else change(x,y);
		}else if(muki == 2){
			if(x != 0 && wall_x[x - 1][y] == 1){
				flag = 0;
				printf("L");
				x--;
			}else change(x,y);
		}else if(muki == 3){
			if(y != 0 && wall_y[x][y - 1] == 1){
				flag = 0;
				printf("U");
				y--;
			}else change(x,y);
		}
	}while(x != 0 || y != 0);
	return 0;
}

void change(int x,int y){
	int i;
	if(!flag){
		flag = 1;
		muki = (muki + 3) % 4;
	}
	else muki = (muki + 1) % 4;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
long i,j,k;
string s[9];
for(i=0;i<9;i++)cin>>s[i];
i=j=k=0;
cout<<"R";j++;
for(;;){
     if(k==0&&i>0&&s[i-1][j]=='1'){cout<<"U";i-=2;k=3;}
else if(k==0&&     s[i][j]  =='1'){cout<<"R";j++; k=0;}
else if(k==0&&i<8&&s[i+1][j]=='1'){cout<<"D";i+=2;k=1;}
else if(k==0)                     {cout<<"L";j--; k=2;}
else if(k==1&&     s[i][j]  =='1'){cout<<"R";j++; k=0;}
else if(k==1&&i<8&&s[i+1][j]=='1'){cout<<"D";i+=2;k=1;}
else if(k==1&&j>0&&s[i][j-1]=='1'){cout<<"L";j--; k=2;}
else if(k==1)                     {cout<<"U";i-=2;k=3;}
else if(k==2&&i<8&&s[i+1][j]=='1'){cout<<"D";i+=2;k=1;}
else if(k==2&&j>0&&s[i][j-1]=='1'){cout<<"L";j--; k=2;}
else if(k==2&&i>0&&s[i-1][j]=='1'){cout<<"U";i-=2;k=3;}
else if(k==2)                     {cout<<"R";j++; k=0;}
else if(k==3&&j>0&&s[i][j-1]=='1'){cout<<"L";j--; k=2;}
else if(k==3&&i>0&&s[i-1][j]=='1'){cout<<"U";i-=2;k=3;}
else if(k==3&&     s[i][j]  =='1'){cout<<"R";j++; k=0;}
else if(k==3)                     {cout<<"D";i+=2;k=1;}
if(i==0&&j==0)break;
}
cout<<endl;
return 0;
}

C++: #include "stdio.h"
#include "math.h"

#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
using namespace std;
typedef long long  ll;

/** Problem0037 : Path on a Grid **/
int main()
{
	bool wall[6][6][4]={0};
	string s;
	int y=1;
	rep(k, 9) {
		cin >> s;
		if (s.length()==4) {
			rep(x, 4) {
				if (s[x]=='1') {
					wall[x+1][y-1][3]=true;
					wall[x+1][y][2]=true;
				}
			}
		} else if (s.length()==5) {
			REP(x, 1, 6) {
				if (s[x-1]=='1') {
					wall[x-1][y][1]=true;
					wall[x][y][0]=true;
				}
			}
			y++;
		}
	}
	wall[0][0][3]=true; wall[0][1][2]=true;
	
	int x=1, d=1; y=0;
	cout << "R";
	while (1) {
		switch (d) {
			case 1:
				if (wall[x][y][1]) {
					if (wall[x][y][2]) {
						d=0;
						cout << "U";
					} else {
						y--; d=2;
						cout << "RU";
					}
				} else if (wall[x+1][y][3]) {
					x++; d=1;
					cout << "R";
				} else if (wall[x][y+1][1]) {
					y++; x++; d=3;
					cout << "D";
				} else {
					y++; d=0;
				} break;
				
			case 3:
				if (wall[x][y][3]) {
					if (wall[x][y][1]) {
						d=2;
						cout << "R";
					} else {
						x++; d=1;
						cout << "DR";
					}
				} else if (wall[x][y+1][0]) {
					y++; d=3;
					cout << "D";
				} else if (wall[x-1][y][3]) {
					x--; y++; d=0;
					cout << "L";
				} else {
					x--; d=2;
				} break;
				
			case 0:
				if (wall[x][y][0]) {
					if (wall[x][y][3]) {
						d=1;
						cout << "D";
					} else {
						y++; d=3;
						cout << "LD";
					}
				} else if (wall[x-1][y][2]) {
					x--; d=0;
					cout << "L";
				} else if (wall[x][y-1][0]) {
					x--; y--; d=2;
					cout << "U";
				} else {
					y--; d=1;
				} break;
				
			case 2:
				if (wall[x][y][2]) {
					if (wall[x][y][0]) {
						d=3;
						cout << "L";
					} else {
						x--; d=0;
						cout << "UL";
					}
				} else if (wall[x][y-1][1]) {
					y--; d=2;
					cout << "U";
				} else if (wall[x+1][y][2]) {
					x++; y--; d=1;
					cout << "R";
				} else {
					x++; d=3;
				} break;
		}
		cout << flush;
		if (d==2 && x==0 && y==1)
			break;
		if (d==0 && x==0 && y==1)
			break;
	}
	cout << endl;
	return 0;
}