Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	for stdin.Scan() {
		l := strings.Split(stdin.Text(), " ")
		if l[0] == "0" {
			break
		}
		h, _ := strconv.Atoi(l[0])
		w, _ := strconv.Atoi(l[1])

		tile := make([][]rune, h)
		done := make([][]bool, h)
		for i := 0; i < h; i++ {
			stdin.Scan()
			s := stdin.Text()
			tile[i] = make([]rune, w)
			done[i] = make([]bool, w)
			for j, c := range s {
				tile[i][j] = c
			}
		}
		i, j := 0, 0
		for tile[i][j] != '.' {
			if done[i][j] {
				i = -1
				break
			}
			done[i][j] = true
			switch tile[i][j] {
			case '>':
				j++
			case '<':
				j--
			case '^':
				i--
			case 'v':
				i++
			}
		}
		if i < 0 {
			fmt.Println("LOOP")
		} else {
			fmt.Println(j, i)
		}
	}
}

C++: #include <stdio.h>
#include <stdlib.h>

typedef struct {
	int x;
	int y;
} posn;

posn* next(posn *now, char bord[128][128], int W, int H) {
	posn* ans;

	ans = (posn*)malloc(sizeof(posn));

	switch(bord[now->y][now->x]) {
		case '>' : if(now->x < W - 1)
					   ans->x = now->x + 1;
				   else
					   ans->x = now->x;
				   break;

		case '<' : if(now->x > 0)
					   ans->x = now->x - 1;
				   else
					   ans->x = now->x;
				   break;

		case 'v' : if(now->y < H - 1)
					   ans->y = now->y + 1;
				   else
					   ans->y = now->y;
				   break;

		case '^' : if(now->y > 0)
					   ans->y = now->y - 1;
				   else
					   ans->y = now->y;
				   break;

		case '.' : ans->x = now->x;
				   ans->y = now->y;
	}

	return ans;
}

int main() {
	int W , H;
	char bord[128][128];
	int count = 0;
	posn now;
	posn *temp;

	int i, j;

	while(1) {
		scanf("%d %d", &H, &W);
		if(W == 0 && H == 0)
			break;

		for(i = 0; i < H; i++)
			scanf("%s", bord[i]);

		now.x = 0; now.y = 0;

		count = 0;
		while(count < W * H) {
			temp = next(&now, bord, W, H);
		
			if(temp->x == now.x && temp->y == now.y)
				break;
			
			else {
				now.x = temp->x;
				now.y = temp->y;
			}

			count++;
			free(temp);
		}

		if(count == W * H)
			printf("LOOP\n");
		else
			printf("%d %d\n", now.x, now.y);

	}
	
	return 0;
}

C++: #include<iostream>
#include <cstdio>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)




int main(void){
	int w,h;
	char map[100][100];
	while(cin >> w >> h,w|h){
		rep(j,h)
			rep(i,w)
				cin >> map[i][j];
		int x=0,y=0;
		while(true){
			if(map[x][y]=='@'){
				cout << "LOOP" << endl;
				break;
			}
			if(map[x][y]=='>'){
				x++;
				map[x-1][y]='@';
			}else if(map[x][y]=='<'){
				x--;
				map[x+1][y]='@';
			}else if(map[x][y]=='v'){
				y++;
				map[x][y-1]='@';
			}else if(map[x][y]=='^'){
				y--;
				map[x][y+1]='@';
			}else{
				cout << x << " " << y << endl;
				break;
			}
		}
	}
	return 0;
}

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

int H, W;

void solve() {
	string b[100];
	for (int i = 0; i < H; i++) {
		cin >> b[i];
	}

	bool visited[100][100] = {0};
	int x = 0, y = 0;

	while (b[y][x] != '.') {
		if (visited[y][x]) {
			cout << "LOOP" << endl;
			return;
		}
		visited[y][x] = true;
		if (b[y][x] == '^') y--;
		if (b[y][x] == 'v') y++;
		if (b[y][x] == '<') x--;
		if (b[y][x] == '>') x++;
	}

	cout << x << " " << y << endl;
}

int main() {
	while (cin >> H >> W , H) {
		solve();
	}
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>

using namespace std;

#define all(c) c.begin(),c.end()
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

typedef long long ll;
typedef vector<int> vi;

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& val){
    os << "[ ";
    for(typename vector<T>::const_iterator it=val.begin();
        it != val.end();++it){
        os << *it << " ";
    }
    os << "]";
    return os;
}
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};

inline int mc(char c){
// '>' (大なり記号): 東向きの矢印が書かれたタイル
// '<' (小なり記号): 西向きの矢印が書かれたタイル
// '^' (べき記号) : 北向きの矢印が書かれたタイル
// 'v' (小文字ブイ): 南向きの矢印が書かれたタイル
// '.' (ピリオド) : 何も書かれていないタイル
    switch(c){
    case '>':
        return 0;
    case '<':
        return 2;
    case '^':
        return 1;
    case 'v':
        return 3;
    case '.':
        return -1;
    }
    return -1;
}

string solve(vector<string> field){

    int W = field[0].size();
    int H = field.size();
    vector<vector<char> > alr(H,vector<char>(W,false));

    int nx = 0;
    int ny = 0;
    while(mc(field[ny][nx]) != -1){
        if(alr[ny][nx]){
            return "LOOP";
        }
        alr[ny][nx] = true;
        int d = mc(field[ny][nx]);
        ny += dy[d];
        nx += dx[d];
    }
    stringstream ss;
    ss << nx << " " << ny;
    return ss.str();
}
int main(){
    while(true){
        int W,H;
        cin >> H >> W;
        if(W == 0 and H == 0) break;
        vector<string> field(H);
        for(int i=0;i<H;i++){
            cin >> field[i];
        }
        cout << solve(field) << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<stdlib.h>

int magicalTiles();

void listen_matrixSize(int &,int &);
void listen_matrix(std::vector<std::string> &,const int);
void calc_goalPosition(std::vector<std::string> &,int &,int &,const int,const int);
const int LOOPFLAG=999999;
bool is_loop(const int);

//--------------------------------main------------------------------------

int main()
{
	while(magicalTiles());
	
	return 0;
}

int magicalTiles()
{
	using namespace std;
	int height,width;
	listen_matrixSize(height,width);
	if(!height && !width)
	{
		return 0;
	}
	
	vector<string> matrix;
	listen_matrix(matrix,height);
	
	int goal_h,goal_w;
	if(calc_goalPosition(matrix,goal_h,goal_w,height,width),is_loop(goal_h))
	{
		cout<<"LOOP"<<endl;
	}
	else
	{
		cout<<goal_w<<" "<<goal_h<<endl;
	}
	
	return 1;
}

//-----------------------------------------------------------------------------

void listen_matrixSize(int &height,int &width)
{
	using namespace std;
	
	cin>>height>>width;
}

void listen_matrix(std::vector<std::string> &matrix,const int height)
{
	using namespace std;
	
	string tmp_tile;
	for(int loop_h=0;loop_h<height;loop_h++)
	{
		cin>>tmp_tile;
		matrix.push_back(tmp_tile);
	}
}

void calc_goalPosition(std::vector<std::string> &matrix,int &goal_h,int &goal_w,const int height,const int width)
{
	using namespace std;
	
	int reachedPosition[height][width];
	for(int init_h=0;init_h<height;init_h++)
	{
		for(int init_w=0;init_w<width;init_w++)
		{
			reachedPosition[init_h][init_w]=0;
		}
	}
	
	int current_h=0,current_w=0;
	for(;1;)
	{
		if(!reachedPosition[current_h][current_w])
		{
			reachedPosition[current_h][current_w]=1;
		}
		else
		{
			goal_h=LOOPFLAG;
			return;
		}
		switch(matrix[current_h].at(current_w))
		{
		case '^':
			current_h--;
			break;
		case 'v':
			current_h++;
			break;
		case '<':
			current_w--;
			break;
		case '>':
			current_w++;
			break;
		case '.':
			goal_h=current_h;
			goal_w=current_w;
			return;
		default:
			cout<<"unknown tile inputed"<<endl;
			abort();
		}
	}
}

bool is_loop(const int goal_h)
{
	if(goal_h==LOOPFLAG)
	{
		return true;
	}
	else
	{
		return false;
	}
}