Go: package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	// var w, h int
	for scanner.Scan() {
		// fmt.Scanf("%d %d", &w, &h)

		input := strings.Split(scanner.Text(), " ")
		w, _ := strconv.Atoi(input[0])
		h, _ := strconv.Atoi(input[1])

		if w == 0 && h == 0 {
			return
		}

		isArrive := make([][]bool, w)
		tiles := make([][]string, w)

		for i := 0; i < w; i++ {
			rowArrive := make([]bool, h)
			rowTiles := make([]string, h)
			scanner.Scan()
			row := scanner.Text()
			for j := 0; j < h; j++ {
				rowTiles[j] = string(row[j])
			}
			tiles[i] = rowTiles
			isArrive[i] = rowArrive
		}

		var i, j int
		isEnd := false
		for {
			if isArrive[i][j] == true {
				fmt.Println("LOOP")
				break
			}
			isArrive[i][j] = true

			switch tiles[i][j] {
			case ">":
				j++
			case "^":
				i--
			case "v":
				i++
			case "<":
				j--
			case ".":
				isEnd = true
			}

			if isEnd == true {
				fmt.Println(j, i)
				break
			}
		}
	}
}

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;
		}
	}
	
}

C++: #include<cstdio>
char tile[101][101];
int stat[101][101];
int main(void)
{
	int x,y;
	
	while(scanf("%d %d",&y,&x)!=EOF)
	{
		if(x==0||y==0)break;
		int now_x=0,now_y=0;
		fflush(stdin);
		for(int f1=0;f1<y;f1++)
		{
			scanf("%s",tile[f1]);
		}
		while(1){
			switch(tile[now_y][now_x])
			{
			case '>':
				now_x++;
				break;
			case '<':
				now_x--;
				break;
			case '^':
				now_y--;
				break;
			case 'v':
				now_y++;
				break;
			case '.':
				printf("%d %d\n",now_x,now_y);
				goto G;
			}
		//	printf("now->%d %d\n",now_x,now_y);
			if(stat[now_y][now_x])
			{
				printf("LOOP\n");
				goto G;
			}
			stat[now_y][now_x]=1;
		}
		G:;
		for(int f1=0;f1<101;f1++)
		{
			for(int f2=0;f2<101;f2++)
			{
				tile[f1][f2]='\0';
				stat[f1][f2]=0;
			}
		}
		now_x=0;now_y=0;
	}
	/*
	fflush(stdin);
	getchar();
	*/
	return 0;
}

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


int main()
{
	int w,k,hyou[100][100],i,j,checki[100],check[100],l=0;
	memset(check,0,100*sizeof(int));
	char a;
	while(1)
	{
		scanf("%d%d",&w,&k);
		if(w==0)
			break;
		scanf("%c",&a);
		for(i=0;i<w;i++)
		{
			for(j=0;j<=k;j++)
			{
				scanf("%c",&a);
				if(a=='>')
					hyou[i][j]=1;
				else	if(a=='<')
					hyou[i][j]=2;
				else if(a=='v')
					hyou[i][j]=3;
				else if(a=='^')
					hyou[i][j]=4;
				else if(a=='.')
					hyou[i][j]=0;
				else 
					hyou[i][j]=6;
			}
			
			
		}
		i=0;
		j=0;
		while(hyou[i][j]!=5&&hyou[i][j]!=0)
		{
			switch(hyou[i][j])
			{
			case 1:
				hyou[i][j]=5;
				j++;
				break;
			case 2:
				hyou[i][j]=5;
				j--;
				break;
			case 3:
				hyou[i][j]=5;
				i++;
				break;
			case 4:
				hyou[i][j]=5;
				i--;
				break;
			case 0:
				check[l]=i;
				checki[l]=j;
				break;
			case 5:
				check[l]=0;
				break;
			}
		}
		if(hyou[i][j]==0)
			check[l]=i;
			checki[l]=j;
		l++;
	}
	for(i=0;i<l;i++)
	{
		if(check[i]==0)
			printf("LOOP\n");
		else
			printf("%d %d\n",checki[i],check[i]);
	}
	return 0;
}

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

using namespace std;
char map[100][100];
int H, W;
int x = 0, y = 0;
bool check(){
	if (map[x][y] == 0){
		cout << "LOOP" << endl;
		return true;
	}
	else{
		return false;
	}
}
int main(){
	
	while (1){

		int x = 0, y = 0;
		map[100][100] = {};
		cin >> H >> W;

		if (H == 0 && W == 0){ break; }
		for (int i = 0; i < H; i++){
			for (int j = 0; j < W; j++){
				cin >> map[i][j];
			}
		}
		while (1){
			if (check() == true){ break; }
			if (map[x][y] == '>'){
				x++;
			}
			else if(map[x][y]=='v'){
				y--;
			}
			else if (map[x][y] == '<'){
				x--;;
			}
			else if (map[x][y] == '^'){
				y++;
			}
			else if (map[x][y] == '.'){
				cout << x << " " << y << endl;
				break;
			}
			
			map[x][y] = 0;

		}
	}
	return 0;
}

C++: #include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main() {
    int h,w;
    while(cin>>h>>w){
        if(h==0 && w==0)break;
        
        char fie[200][200]={};
        rep(i,h) rep(j,w) cin>>fie[i][j];
        
        int y=0,x=0;
        bool visited[200][200]={};
        while(1){
            if(fie[y][x]=='.')break;
            else if(visited[y][x]){
                cout<<"LOOP"<<endl;
                goto next;
            }
            visited[y][x]=true;
            
            int here=fie[y][x];
            if(here=='>')x++;
            else if(here=='<')x--;
            else if(here=='^')y--;
            else if(here=='v')y++;
            else cout<<"error"<<endl;
            
        }
        cout<<x<<" "<<y<<endl;
        next:;
    }
    
    return 0;
}

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

char map[101][101] ;
char d[] = { '>' , 'v' , '<' , '^' } ;
int dx[] = { 1,0,-1,0 } ;
int dy[] = { 0,1,0,-1 } ;

void move( int y , int x ){
	if( map[y][x] == '.' ) cout << x << ' ' << y << endl ;
	else if( map[y][x] == '0' ) cout << "LOOP" << endl ;
	else {
		for( int j=0 ; j<4 ; j++ ){
			if( map[y][x] == d[j] ){
				map[y][x] = '0' ;
				move( y+dy[j] , x+dx[j] ) ;
			}
		}
	}
}

int main(){
	
	int h , w ;
	
	while( cin >> h >> w , h ){
		for( int i=0 ; i<h ; i++ ){
			for( int j=0 ; j<w ; j++ ){
				cin >> map[i][j] ;
			}
		}
		
		move(0,0) ;
	}
	
return 0 ;
}