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<cstdio>
using namespace std;
int g_x,g_y;
char field[100][100];
void solve(int y,int x);
int main(){

    int h,w;
    while(scanf("%d %d",&h,&w),!h==0 && !w==0){
        for(int i=0;i<h;i++){
            scanf("%s",field[i]);
        }
        solve(0,0);
        if(g_x==0 && g_y==0)puts("LOOP");
        else printf("%d %d\n",g_x,g_y);
    }
    return 0;

}

void solve(int y,int x){
    if(field[y][x]=='0'){
        g_x=g_y=0;
        return;
    }
    if(field[y][x]=='.'){
        g_x=x;
        g_y=y;
        return;
    }
    if(field[y][x]=='>'){
        field[y][x]='0';
        solve(y,x+1);
    }
    if(field[y][x]=='<'){
        field[y][x]='0';
        solve(y,x-1);
    }
    if(field[y][x]=='^'){
        field[y][x]='0';
        solve(y-1,x);
    }
    if(field[y][x]=='v'){
        field[y][x]='0';
        solve(y+1,x);
    }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define mp make_pair



int main(){
    typedef vector<string> vs;
    int h, w;
    while (cin >> h >> w, h | w){
        vs G(h);
        for (auto & a : G) cin >> a;

        vector<vector<bool>> vis(h, vector<bool>(w, false));
        int cx = 0, cy = 0;
        const int dx[] = { 1, 0, -1, 0 };
        const int dy[] = { 0, -1, 0, 1 };

        map<char, int> m;
        m['>'] = 0, m['^'] = 1, m['<'] = 2, m['v'] = 3;

        while (1){
            if (vis[cy][cx]){
                cout << "LOOP" << endl;
                goto end;
            }
            vis[cy][cx] = true;
            char c = G[cy][cx];
            if (c == '.'){
                cout << cx << " " << cy << endl;
                goto end;
            }
            cx += dx[m[c]], cy += dy[m[c]];
        }
    end:;
    }
}

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

using namespace std;

int main(){
	int n,m,k,l;
	char a[105][105];
	while(1){
		scanf("%d %d",&n,&m);
		if( n==0 && m==0 ) break;
		k=0; l=0;
		for(int i=0 ; i<n ; i++ ){
			scanf("%s",&a[i]);	
		}
		int b[105][105]={0};
		while(1){
			if(a[k][l]=='.'){
				printf("%d %d\n",l,k);
				break;
			}
			if(b[k][l]==1){
				printf("LOOP\n");
				break;
			}
			if(a[k][l]=='>'){
				b[k][l]=1;
				l++;
				continue;
			}
			if(a[k][l]=='v'){
				b[k][l]=1;
				k++;
				continue;
			}
			if(a[k][l]=='<' ){
				b[k][l]=1;
				l--;
				continue;
			}
			if(a[k][l]=='^' ){
				b[k][l]=1;
				k--;
				continue;
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;



int main(void){

int w, h;
string ss;
	while(cin >> h >> w ){
		if(h==0 && w==0 || cin.eof()) break;
		vector<string> bd(h);
		vector<vector<char> > lc(h,vector<char>(w,' '));
		rep(i,h) cin >> bd[i];
		int y=0, x=0, loop=0;
		while(1){
			if(x<0 || y<0 || x>=w || y >=h) {loop=99;break;}
			if(lc[y][x]=='z'){ loop=1; break; }
			lc[y][x] = 'z';
			if(bd[y][x]=='.') break;
			else if(bd[y][x]=='>') x++;
			else if(bd[y][x]=='<') x--;
			else if(bd[y][x]=='^') y--;
			else if(bd[y][x]=='v') y++;
		}
		if(loop>0 && loop < 90) cout << "LOOP" << endl;
		else if(loop==0) cout << x << " " << y << endl;
	}
	return 0;
	
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <set>
using namespace std;
typedef pair<int,int> P;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define EQ(a,b) (abs((a)-(b))<EPS)
char map[110][110];
int main()
{
	while(1)
	{
		int w,h;
		cin >> w >> h;
		if(w==0&&h==0)break;
		for(int i=0;i<w;i++)
		{
			for(int j=0;j<h;j++)
			{
				cin >> map[i][j];
			}
		}
		int x=0,y=0;
		int count=0;
		bool flag=false;
		while(1)
		{
			if(map[x][y]=='>')
			{
				y++;
			}
			if(map[x][y]=='<')
			{
				y--;
			}
			if(map[x][y]=='v')
			{
				x++;
			}
			if(map[x][y]=='^')
			{
				x--;
			}
			if(map[x][y]=='.')
			{
				break;
			}
			count++;
			if(count>11000)
			{
				flag=true;
				break;
			}

		}
		if(flag)
		{
			cout << "LOOP" << endl;
		}
		else
		{
			cout << y << ' ' << x << endl;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
char s[101][101];
int n,m,a[100][100],c;
using namespace std;
int dfs(int y,int x){
  if(a[y][x]++)return 0;
  if(s[y][x]=='.'){cout<<x<<' '<<y<<endl;c++;}
  else if(s[y][x]=='^')dfs(y-1,x);
  else if(s[y][x]=='v')dfs(y+1,x);
  else if(s[y][x]=='>')dfs(y,x+1);
  else if(s[y][x]=='<')dfs(y,x-1);
  if(c)return 1;
  return 0;
}
int main(){
  while(cin>>n>>m,n){c=0;
    rep(i,100)rep(j,100)a[i][j]=0;
    rep(i,n)rep(j,m)cin>>s[i][j];
    if(!dfs(0,0))cout<<"LOOP"<<endl;
  }
}

C++: #include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
#include <map>
using namespace std;
void tile(int *x,int *y,char d[101][101] ){
	if(d[*y][*x]=='m')
		*x=50000;
	else if(d[*y][*x]!='.'){
	if(d[*y][*x]=='>'){
	d[*y][*x]='m';
		*x=*x+1;
	}
	else if(d[*y][*x]=='<'){
	d[*y][*x]='m';
		*x=*x-1;
	}
	else if(d[*y][*x]=='^'){
		d[*y][*x]='m';
		*y=*y-1;
	}
	else if(d[*y][*x]=='v'){
		d[*y][*x]='m';
		*y=*y+1;
	}
		tile(x,y,d);
	}
	
}
int main(){
	
	int w,h;
	
	while(cin>>h>>w,h!=0&&w!=0){
	char d[101][101];
	int x=0,y=0;
	
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>d[i][j];
		}
	}
	tile(&x,&y,d);
	
	if(x==50000)
		cout<<"LOOP"<<endl;
	else
		cout<<x<<" "<<y<<endl;
	}
	
}

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