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

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

		if(H == 0 && W == 0)
		{
			break;
		}
		char map[200][200];
		/*for(int i = 0; i < 200; i++)
		{
			for(int j = 0; j < 200; j++)
			{
				map[i][j] = -1;
			}
		} */
		for(int iy = 0; iy < H; iy++)
		{
			for(int jx = 0; jx < W; jx++)
			{
				cin >> map[iy][jx];
			}
		}

		int px = 0;
		int py = 0;
		int count = 0;
		while(count < 10001)
		{
			if(map[py][px] == '>')
			{
				px++;
			}
			else if(map[py][px] == '<')
			{
				px--;
			}
			else if(map[py][px] == '^')
			{
				py--;
			}
			else if(map[py][px] == 'v')
			{
				py++;
			}
			else
			{
				cout << px << " " << py << endl;
				break;
			}
			count++;
		}
		if(count >= 10001)
		{
			cout << "LOOP" << endl;
		}

	}
	

}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; ++i)
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define P pair<int, int>

int main() {
  int w, h;
  while(cin >>w >>h && w){
    vector<string> v(h);
    REP(i, h) cin >>v[i];
    vector< vector<bool> > visited(h, vector<bool>(w, false));
    int ny = 0, nx = 0;
    while(v[ny][nx] != '.' && !visited[ny][nx]){
      visited[ny][nx] = true;
      if(v[ny][nx] == '>') ++nx;
      if(v[ny][nx] == '<') --nx;
      if(v[ny][nx] == 'v') ++ny;
      if(v[ny][nx] == '^') --ny;
    }
    if(!visited[ny][nx]) cout <<nx <<" " <<ny <<endl;
    else cout <<"LOOP" <<endl;
  }
  return 0;
}

C++:  #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int main()
 {
   int w,h;
   bool flag=false;
   char map[100+5][100+5];
   while(cin>>w>>h&&(w||h))
   {
     for(int i=0;i<h;i++)
     {
       for(int j=0;j<w;j++)
       {
         cin>>map[i][j];        
       }        
     }               
     int step=0;
     int x=0;
     int y=0;
     while(1)
     {
       while(map[x][y]=='>') 
       {
         x++;
         step++;
         //cout<<">"<<" ";                      
       }        
       while(map[x][y]=='<')
       {
         x--;
         step++;   
         //cout<<"<"<<" ";                   
       }
       while(map[x][y]=='v')
       {
         y++;
         step++;         
         //cout<<"v"<<" ";             
       }
       while(map[x][y]=='^')
       {
         y--;
         step++;         
         //cout<<"^"<<" ";             
       }
       if(step>(w*h))
       {
         flag=true;
         break;            
       }
       if(map[x][y]=='.')
       {
         break;                  
       }
       if(flag) break;
     }        
     if(flag) cout<<"LOOP"<<endl;
     else cout<<x<<" "<<y<<endl;
   }
   //while(1);
   return 0;
 }

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

using namespace std;

char data[101][101];

pair<int, int> search(pair<int, int> p);

int main()
{
    int n, m;

    while (cin >> n >> m, n || m) {
        for (int i = 0; i < n; i++) {
            cin >> data[i];
        }
        bool c[101][101] = {false};
        pair<int, int> pos = make_pair(0, 0);
        while (1) {
            pair<int, int> np = search(pos);
            if (np == pos) {
                cout << pos.second << " " << pos.first << endl;
                break;
            } else {
                pos = np;
            }
            if (c[pos.first][pos.second]) {
                puts("LOOP");
                break;
            } else {
                c[pos.first][pos.second] = true;
            }
        }
    }
    return 0;
}

pair<int, int> search(pair<int, int> p)
{
    if (data[p.first][p.second] == 'v') {
        return make_pair(p.first+1, p.second);
    } else if (data[p.first][p.second] == '^') {
        return make_pair(p.first-1, p.second);
    } else if (data[p.first][p.second] == '>') {
        return make_pair(p.first, p.second+1);
    } else if (data[p.first][p.second] == '<') {
        return make_pair(p.first, p.second-1);
    } else {
        return p;
    }
}

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

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll; 
typedef pair<ll, ll> P;
typedef pair<string, ll> PS;

int H, W;
char c[110][110];	
bool f[110][110];

void solve(int y, int x){
	if (f[y][x]){
		cout << "LOOP\n";
		return;
	}
	if (c[y][x] == '.'){
		cout << x << " " << y << endl;
		return;
	}	
	f[y][x] = 1;
	if (c[y][x] == '>'){
		solve(y, x + 1);
	}
	else if (c[y][x] == 'v'){
		solve(y + 1, x);
	}
	else if (c[y][x] == '<'){
		solve(y, x - 1);
	}
	else{
		solve(y - 1, x);
	}
}

int main(){
	while (cin >> H >> W){
		if (H + W == 0)break;
		REP(i, H){
			REP(j, W){
				cin >> c[i][j];
			}
		}
		solve(0, 0);
		REP(i, H){
			REP(j, W){
				f[i][j] = 0;
			}
		}
	}
}

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

string map[110];
int j_map[110][110];
int* ans(int* x){
	if(j_map[x[0]][x[1]]==1){
		x[0]=x[1]=-1;
		return x;
	}else{
		j_map[x[0]][x[1]]=1;
		
		if(map[x[0]][x[1]]=='v'){
			x[0]++;
			return ans(x);
		}else if(map[x[0]][x[1]]=='<'){
			x[1]--;
			return ans(x);
		}else if(map[x[0]][x[1]]=='>'){
			x[1]++;
			return ans(x);
		}else if(map[x[0]][x[1]]=='^'){
			x[0]--;
			return ans(x);
		}else{
			return x;
		}
	}
}



int main(){
	int w,h;
	while(cin>>w,cin>>h,(w!=0)&&(h!=0)){
		for(int i=0;i<w;i++){
			cin>>map[i];
		}
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				j_map[i][j]=0;
			}
		}
		
		int* x=(int *)malloc(sizeof(int)*2);
		x[0]=x[1]=0;
		x = ans(x);
		if(x[0]==-1){
			cout<<"LOOP"<<endl;
		}else{
			cout<<x[1]<<" "<<x[0]<<endl;
		}
	}
	
}