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>
using namespace std;
int main(void){
    int x,y;
    int h,w;
    string in;
    while(true) {
        char** stage;
        bool** nowplace;
        cin >> h;
        cin >> w;
        cin.ignore();
        if (h == 0) {
            break;
        }
        stage = new char*[h];
        nowplace = new bool*[h];
        for(int i = 0; i < h; ++i) {
            stage[i] = new char[w];
            nowplace[i] = new bool[w];
        }
        for(int i = 0; i < h; ++i) {
            getline(cin, in);
            for(int j = 0; j < w; ++j) {
                stage[i][j] = in[j];
                nowplace[i][j] = false;
            }
        }
        x = 0;
        y = 0;
    char now;
        while(true) {
            now = stage[y][x];
            if (now == '.') {
                cout << x << " " << y << endl;
                break;
            }
            else {
                if (nowplace[y][x] == false) {
                    nowplace[y][x] = true;
                }
                else {
                    cout << "LOOP" << endl;
                    break;
                }
                if (now == '>') {
                    ++x;
                }
                else if (now == '<') {
                    --x;
                }
                else if (now == '^') {
                    --y;
                }
                else if (now == 'v') {
                    ++y;
                }
            }
        }
        for(int i = 0; i < h; ++i) {
            delete [] stage[i];
            delete [] nowplace[i];
        }
        delete [] stage;
        delete [] nowplace;
    }
}

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

using namespace std;

char f[128][128];
int judge[128][128];
int ex, ey;

int main()
{
	int w, h;
	int i, j;
	while(cin >> h >> w)
	{
		if(h == 0 && w == 0) break;

		i = 0; j = 0;

		for(int k = 0; k < h; k++)
		{
			cin >> f[k];
		}
		while(1)
		{
			if(judge[i][j] == 1)
			{
				ex = -1; ey = -1;
				break;
			}
			else if(f[i][j] == '.')
			{
				ex = j; ey = i;
				break;
			}

			judge[i][j] = 1;

			if(f[i][j] == '>')
			{
				++j;
			}
			else if(f[i][j] == '<')
			{
				--j;
			}
			else if(f[i][j] == '^')
			{
				--i;
			}
			else if(f[i][j] == 'v')
			{
				++i;
			}
		}

		if(ex == -1 && ey == -1)
		{
			cout << "LOOP" << endl;
		}
		else
		{
			cout << ex << ' ' << ey << endl;
		}
	}
}

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>>h>>w&&(w||h))
   {
     int map2[100+5][100+5]={{0}};
     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)
     {
       if(map2[x][y]==1) 
       {
         flag=true;
         break;                  
       }
       if(map[x][y]=='>') 
       {
         map2[x][y]=1;
         y++;
         step++;
         //cout<<">"<<" ";                      
       }        
       if(map[x][y]=='<')
       {
         map2[x][y]=1;
         y--;
         step++;   
         //cout<<"<"<<" ";                   
       }
       if(map[x][y]=='v')
       {
         map2[x][y]=1;
         x++;
         step++;         
         //cout<<"v"<<" ";             
       }
       if(map[x][y]=='^')
       {
         map2[x][y]=1;
         x--;
         step++;         
         //cout<<"^"<<" ";             
       }
       if(map[x][y]=='.')
       {
         break;                  
       }
       if(flag) break;
     }        
     if(flag) cout<<"LOOP"<<endl;
     else cout<<y<<" "<<x<<endl;
   }
   //while(1);
   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;}
		if(hyou[i][j]==5)
			check[l]=-1;
		l++;
	}
	for(i=0;i<l;i++)
	{
		if(check[i]==-1)
			printf("LOOP\n");
		else
			printf("%d %d\n",checki[i],check[i]);
	}
	return 0;
}

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

char board[100][100];
bool hasArrived[100][100];

int main() {
	int h, w;
	while (std::cin >> h >> w, h + w != 0) {
		for (int y = 0; y < h; ++y)
			for (int x = 0; x < w; ++x)
				std::cin >> board[x][y];

		int px = 0, py = 0;
		while (true) {
			if (hasArrived[px][py]) {
				std::cout << "LOOP" << std::endl;
				break;
			}

			hasArrived[px][py] = true;

			if (board[px][py] == '.') {
				std::cout << px << " " << py << std::endl;
				break;
			}
			
			if (board[px][py] == '>')
				++px;
			else if (board[px][py] == '<')
				--px;
			else if (board[px][py] == 'v')
				++py;
			else if (board[px][py] == '^')
				--py;
		}

		std::memset(board, 0, sizeof(board));
		std::memset(hasArrived, 0, sizeof(hasArrived));
	}
}

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