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 <iostream>
#include <stdio.h>
#include <time.h>
#include<string>
using namespace std;
int main(){
	char tile[101][101];
	int dp[101][101]={0};
	bool finished=false;
	int x,y;
	while(1){
		cin>>y>>x;
		memset(dp,0,sizeof(dp));
		finished=false;
		if(y==0 && x==0){
			break;
		}
		for(int i=0;i<y;i++){
			for(int j=0;j<x;j++){
				cin>>tile[i][j];
			}
		}int i=0,j=0;
		while(1){
			switch(tile[i][j]){
			case '>': j++ ;dp[i][j]++;break;
			case '<': j--;dp[i][j]++;break;
			case '^': i--;dp[i][j]++;break;
			case 'v': i++;dp[i][j]++;break;
			case '.': cout<<j<<" "<<i<<endl;finished=true; break;
			}
			if(finished==true){
				break;
			}
			if(dp[i][j]==2){
				cout<<"LOOP"<<endl;
				break;
			}
		}
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <functional>

using namespace std;

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

int H,W;
char field[110][110];
map<char,int> dx;
map<char,int> dy;

void make(){
  dx['^'] = 0;  dy['^'] = -1;
  dx['v'] = 0;  dy['v'] = 1;
  dx['>'] = 1;  dy['>'] = 0;
  dx['<'] = -1; dy['<'] = 0;
}

pair<int,int> func(int i, int j){
  if(field[i][j] == '.') return make_pair(i,j);
  int cnt = 0;

  while(1){
    if(i < 0 || j < 0 || i >= H || j >= W) continue;
    cnt++;
    i += dy[field[i][j]];
    j += dx[field[i][j]];
    if(field[i][j] == '.') return make_pair(i,j);
    if(cnt > 10000) break;
  }

  return make_pair(-1,-1);
}

int main(){
  int i,j,k;

  make();
  for(; ~scanf("%d %d",&H,&W); ){
    if(H == 0 && W == 0) break;

    rep(i,H) scanf("%s",&field[i]);

    pair<int,int> res = func(0,0), out(-1,-1);
    if(res == out) puts("LOOP");
    else printf("%d %d\n",res.second,res.first);
  }

  return 0;
}

C++: #include<iostream>

std::pair<char,bool> data[101][101];

int main(){
	int w,h;
	while(std::cin>>w>>h){
		if(w==0&&h==0)break;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				std::cin>>data[i][j].first;
				data[i][j].second=false;
			}
		}
		int x=0,y=0;
		while(true){
			if(data[y][x].second){
				std::cout<<"LOOP"<<std::endl;
				break;
			}else data[y][x].second=true;

			if(data[y][x].first=='^')y--;
			if(data[y][x].first=='>')x++;
			if(data[y][x].first=='v')y++;
			if(data[y][x].first=='<')x--;

			if(data[y][x].first=='.'){
				std::cout<<x<<" "<<y<<std::endl;
				break;
			}
		}
	}
	return 0;
}

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

#define FILED (-1)

enum TILE_TYPE{
  TILE_NONE = 0,
  TILE_UP,
  TILE_DOWN,
  TILE_RIGHT,
  TILE_LEFT,

  TILE_TYPE_NUM
};
static const char tile_type[TILE_TYPE_NUM] {
  '.',
  '^',
  'v',
  '>',
  '<'
};
int get_tile_type(char data) {
  for (int i = 0; i < TILE_TYPE_NUM; i++)
    if (data == tile_type[i])
      return i;
  return FILED;
}

struct Tile {
public:
  Tile(int _type) : type(_type), entered(false) {}
  
  void  SetType(int _type) { type = _type; }
  int   GetType(void)      { return type; }
  bool  StepOn(void) {
    bool has_entered = entered;
    entered = true;

    return has_entered;
  }
private:
  int   type;
  bool  entered;
};

struct Pos {
public:
  Pos(int _x, int _y) : x(_x), y(_y) {}
  bool operator ==(const Pos _pos) { 
    return this->x == _pos.x && this->y == _pos.y; 
  }

  int x;
  int y;
};

class TileSet {
public:
  TileSet() { arr.reserve(MAX_ARRAY_SIZE); }
  void Resize(const int h,const int w)
  {
    // ????´???°????¨??????????TILE_NONE??§?????????
    arr.resize(h);
    for (auto &i : arr) {
      i.resize(w, TILE_NONE);
    }
  }
  void Set(const int x, const int y, const int data)
  {
    assert(data != FILED);

    arr[x][y].SetType(data);
  }
  Pos Move(Pos pos)
  {
    switch (arr[pos.x][pos.y].GetType())
    {
    case TILE_NONE:
      return pos;
    case TILE_UP:
      return Pos(pos.x, pos.y - 1);
    case TILE_DOWN:
      return Pos(pos.x, pos.y + 1);
    case TILE_LEFT:
      return Pos(pos.x - 1, pos.y);
    case TILE_RIGHT:
      return Pos(pos.x + 1, pos.y);
    default:
      // ?????????????????£??????????????????
      return pos;
    }
  }

  // ????????????????¨????
  Pos EnterRoom(void)
  {
    Pos pos(0,0);

    while (1)
    {
      Pos now_pos = pos;
      pos = Move(pos);
      //cout << pos.x << " " << pos.y << endl;
      // ??????????????¢????????´?????????????????????
      if (now_pos == pos) return pos;
      // ????????????????????´??????????????????
      if (arr[pos.x][pos.y].StepOn()) return Pos(FILED,FILED);
    }
  }
private:
  static const int MAX_ARRAY_SIZE = 100 * 100;

  vector<vector<Tile>> arr;
  int now_tile_x;
  int now_tile_y;
};

int main() {
  // ???????????????????????\???
  int H, W;
  while(1){
    cin >> H >> W;
    // 0 0 ?????\??????????????¨??????
    if (!(H+W))  break;

    TileSet tile_set;
    tile_set.Resize(W, H);
    for (int y = 0; y < H; y++) {
      for (int x = 0; x < W; x++) {
        char tile_data;
        cin >> tile_data;
        tile_set.Set(x, y, get_tile_type(tile_data));
      }
    }

    // ??????
    Pos pos = tile_set.EnterRoom();

    // ????????¨??????????????£?????????
    if (pos.x == FILED)
      cout << "LOOP" << endl;
    // ?§???????????????????
    else
      cout << pos.x << " " << pos.y << endl;
  }
}

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

int H, W;
char tile[101][101];

void magi(int y, int x);

int main()
{
  while (scanf("%d%d", &H, &W), W || H){
    for (int i = 0; i < H; i++){
      scanf("%s", tile[i]);
    }
    magi(0, 0);
  }

  return (0);
}

void magi(int y, int x)
{
  if (tile[y][x] == '.'){
    printf("%d %d\n", x, y);
  }
  else if (tile[y][x] == '0'){
    puts("LOOP");
  }

  if (0 <= x + 1 && x + 1 <= W - 1 && tile[y][x] == '>'){
    tile[y][x] = '0';
    magi(y, x + 1);
  }
  if (0 <= x - 1 && x - 1 <= W - 1 && tile[y][x] == '<'){
    tile[y][x] = '0';
    magi(y, x - 1);
  }
  if (0 <= y + 1 && y + 1 <= H + 1 && tile[y][x] == 'v'){
    tile[y][x] = '0';
    magi(y + 1, x);
  }
  if (0 <= y - 1 && y - 1 <= H - 1 && tile[y][x] == '^'){
    tile[y][x] = '0';
    magi(y - 1, x);
  }
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int h,w;
	while(cin>>h>>w,w||h){
		char a[h][w];
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cin>>a[i][j];
			}
		}
		bool flag=true;
		int i=0,j=0;
		while(flag){
			flag=true;
			if(a[i][j]=='v'){
				j++;
				a[i][j]='!';
			}
			if(a[i][j]=='>'){
				i++;
				a[i][j]='!';
			}
			if(a[i][j]=='<'){
				i--;
				a[i][j]='!';
			}
			if(a[i][j]=='^'){
				j--;
				a[i][j]='!';
			}
			if(a[i][j]=='.'){
				break;
			}
			if(a[i][j]=='!'){
				flag=false;
			}
		}
		if(!flag){
			cout<<"LOOP"<<endl;
		}
		else{
			cout<<i<<' '<<j<<endl;
		}
	}
}