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 <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit
#include <cstdio>	// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define DEBUG 0
#define TOP 0
#define RIGHT 1
#define BOTTOM 2
#define LEFT 3
#define DEBUG2 0
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
string FILE_NAME = "testcase.Path_on_a_Grid";
string NAME;
string itos (int n )
{
	stringstream ss;
	ss << n;

	return ss.str();
}
int grid[10][10];
const int dr[] = {-1, 0, 1, 0 };
const int dc[] = { 0, 1, 0,-1 };
const char Dir[] = { 'U','R','D','L'};

void touch_wall (int row, int col, int dir, int hand, string & res )
{
	if ((1<<hand & grid[row][col] ) != 0 )
		res += Dir[dir];	
}

int main()
{
//	cut here before submit 
#if DEBUG
	NAME = FILE_NAME;
	int CNT = 1;
	NAME += itos (CNT );
	while (freopen (NAME.c_str() , "r", stdin ) != NULL ) {
#endif
	memset (grid, 0, sizeof (grid ) );
/*
	rep (j, 5 ){
		grid[0][j] |= 1<<TOP;
		grid[5][j] |= 1<<BOTTOM;
	} // end rep
	rep (i, 6 ){
		grid[i][0] |= 1<<LEFT;
		grid[i][4] |= 1<<RIGHT;
	} // end rep
*/
	for (int i = 1; i <= 9; i++ ){
		string s = "";
		cin >> s;
		rep (j, s.length() ){
			if (i % 2 != 0 ){
				if (s[j] == '1' ){
					grid[i/2][j] |= 1<<BOTTOM;
					grid[(i+1)/2][j] |= 1<<TOP;
				} // end if
			}else{
				if (s[j] == '1' ){
					if (j == 0 ){
						grid[i/2][j] |= 1<<LEFT;
					}else{
						grid[i/2][j] |= 1<<LEFT;
						grid[i/2][j-1] |= 1<<RIGHT;
					} // end if
				} // end if
			} // end if
		} // end rep
	} // end for
/*
	rep (i, 6 ){
		rep (j, 5 ){
			cout << setw(2) << grid[i][j];
		} // end rep
		cout << endl;
	} // end rep
*/
	int row = 0, col = 0, dir = RIGHT;
	int hand = (dir+1)%4;
	string res = "";
	while (!(row == 1 && col == 0 && (dir == LEFT ) ) ){
		touch_wall (row, col, dir, hand, res );
		if ((1<<hand & grid[row][col] ) == 0 ){	// 右手の壁がなくなった、なくなった方向に回転
			dir = hand;
		}else
		if ((1<<dir & grid[row][col] ) != 0 ){	
			while ((1<<dir & grid[row][col] ) != 0 ){// 右手の壁があったとしても前に進めない
				dir = (4+dir-1)%4;
				touch_wall (row, col, dir, hand, res );
			} // end while
		} // end if
		row = row + dr[dir];
		col = col + dc[dir];
		hand = (dir+1)%4;
#if DEBUG2
		cout << '(' << row << ',' << col << ')' << " dir: " << dir << endl;
#endif
	} // end while
	touch_wall (row, col, dir, hand, res );

	cout << res << endl;

#if DEBUG
	CNT++;	// cut here before submit
	NAME = FILE_NAME;
	NAME += itos (CNT );
	} // end loop; cut here before submit
#endif			
	return 0;
}

C++: «ã¤èÍz

C++: #include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>

#define X first
#define Y second
#define WIDTH 8
#define HEIGHT 8

using namespace std;

struct point{
	point(int x = 0, int y = 0, char dir = 'R'):x(x), y(y), dir(dir){}
	int x;
	int y;
	char dir;
};

char moveMap(vector<string> &map, point &player){
	switch(player.dir){
	case 'R':
		if(player.y != 0 && map[player.y - 1][player.x + 1] == '1'){
			player.y -= 1;
			player.x += 1;
			player.dir = 'U';
		}
		else if(player.x != map[player.y].size() - 1 && map[player.y][player.x + 1] == '1'){
			player.x += 1;
		}
		else if(player.y != 8 && map[player.y + 1][player.x + 1] == '1'){
			player.y += 1;
			player.x += 1;
			player.dir = 'D';
		}
		break;
	case 'L':
		if(player.y != 8 && map[player.y + 1][player.x] == '1'){
			player.y += 1;
			player.dir = 'D';
		}
		else if(player.x != 0 && map[player.y][player.x - 1] == '1'){
			player.x -= 1;
		}
		else if(player.y != 0 && map[player.y - 1][player.x] == '1'){
			player.y -= 1;
			player.dir = 'U';
		}
		break;
	case 'U':
		if(player.x != 0 && map[player.y - 1][player.x - 1] == '1'){
			player.y -= 1;
			player.x -= 1;
			player.dir = 'L';
		}
		else if(player.y != 1 && map[player.y - 2][player.x] == '1'){
			player.y -= 2;
		}
		else if(player.x != map[player.y].size() - 1 && map[player.y - 1][player.x] == '1'){
			player.y -= 1;
			player.dir = 'R';
		}
		break;
	case 'D':
		if(player.x != map[player.y].size() - 1 && map[player.y + 1][player.x] == '1'){
			player.y += 1;
			player.dir = 'R';
		}
		else if(player.y != 7 && map[player.y + 2][player.x] == '1'){
			player.y += 2;
		}
		else if(player.x != 0 && map[player.y + 1][player.x - 1] == '1'){
			player.y += 1;
			player.x -= 1;
			player.dir = 'L';
		}
		break;
	default:
		break;
	}
	return player.dir;
}

int main(){
	string tmp;
	while(cin >> tmp){
		if(cin.eof()) break;
		
		vector<string> map;
		map.push_back(tmp);
		for(int i = 1; i < 9; i++){
			cin >> tmp;
			map.push_back(tmp);
		}

		point player(0, 0, 'R');
		string root;
		root.push_back('R');
		
		while(1){
			root.push_back(moveMap(map, player));
			if(player.x == 0 && player.y == 0) break;
		}

		for(int i = 0; i < root.size(); i++){
			cout << root[i];
		}
		cout << endl;
	}
	return 0;
}