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 <queue>
#include <string>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

char grid[110][110];

int main(){
    int w,h;
    while(cin>>h>>w, h||w){
        bool vis[110][110]={};
        rep(y,h) cin>>grid[y];
        int px=0, py=0;
        bool loop=false;
        while(1){
            if(vis[py][px]){
                loop=true; break;
            }
            vis[py][px]=true;
            char c=grid[py][px];
            if(c=='.') break;
            else if(c=='>') px++;
            else if(c=='^') py--;
            else if(c=='<') px--;
            else if(c=='v') py++;
        }
        if(loop) cout<<"LOOP"<<endl;
        else cout<<px<<" "<<py<<endl;
    }

}

C++: #include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
	char *map;
	bool *mapb;
	int x,y;
 
	while(1){
		scanf("%d %d",&y,&x);
		if(y==0 || x==0)
			return 0;

		map =(char*)malloc(x*y*sizeof(char));
		mapb = (bool*)malloc(x*y*sizeof(bool));

		for(int i=0;i<y;i++){
			char *buf;
			buf = (char*)malloc(x+1);
			scanf("%s",buf);
			memcpy(&map[x*i],buf,x);
			free(buf);
		}

		int posx=0,posy=0;
		memset(mapb,0,x*y);

		while(map[posy*x+posx]!='.'){
			mapb[posy*x+posx] = 1;   
			switch(map[posy*x+posx]){
  		case '>':
        posx++;
        break;
  		case '<':
        posx--;
        break;
  		case 'v':
        posy++;
        break;
  		case '^':
        posy--;
        break;
			}
			if(mapb[posy*x+posx]==1){
				// passed twice
				printf("LOOP\n");
        posx=-1;
        break;
			}
		}
		if(posx!=-1)
			printf("%d %d\n",posx,posy);
    free(map);
    free(mapb);
	}

	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;
			}
		}
		for(i=0;i<w;i++){
			for(j=0;j<=k;j++){
				if(hyou[i][j]==6)
				printf("\n");
				else
					printf("%d",hyou[i][j]);
			}
		}
		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 <cstdio>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int w,h;
	int dx[128]={0};
	int dy[128]={0};
	dx['<'] = -1;
	dx['>'] = 1;
	dy['^'] = -1;
	dy['v'] = 1;
	while(cin >> w >> h , w){
		char data[128][128]={0};
		rep(i,h)rep(j,w)cin >> data[i][j];
		int x = 0 , y = 0 , f = 0;
		while(data[y][x]!='.'){
			char c = data[y][x];
			if(c == '-'){f = 1 ; break;}
			else data[y][x] = '-';
			x += dx[c] , y += dy[c];
		}
		if(f)cout << "LOOP" << endl;
		else cout << x << " " << y << endl;
	}
}

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<string> lc(h," ");
		rep(i,h) cin >> bd[i];
		int y=0, x=0, loop=0;
		while(1){
			if(bd[y][x]=='>') x++;
			else if(bd[y][x]=='<') x--;
			else if(bd[y][x]=='^') y--;
			else if(bd[y][x]=='v') y++;
			else if(bd[y][x]=='.') break;
			if(lc[y][x]=='z'){ loop=1; break; }
			lc[y][x] = 'z';
		}
		if(loop>0) cout << "LOOP" << endl;
		else cout << x << " " << y << endl;
	}
	return 0;
	
}

C++: #include <iostream>

using namespace std;

char tile[101][101];
bool visited[101][101];

int main(){
	int w,h;
	while(1){
		int x,y;
		cin >> h >> w;
		for(int i=0;i < h;i++)
			for(int j=0;j < w;j++)
				visited[i][j] = false;
		if(!(w|h)) break;
		for(int i=0;i < h;i++)
			for(int j=0;j < w;j++)
			 cin >> tile[i][j];
		x = y = 0;
		while(1){
			if(visited[x][y] == false) visited[x][y] = true;
			else {
				x = y = 10000;break;
			}
			if(tile[x][y] == '>') y++;
			else if(tile[x][y] == 'v') x++;
			else if(tile[x][y] == '^') x--;
			else if(tile[x][y] == '<') y--;
			else if(tile[x][y] == '.') break;
		}
		if(x == 10000){
			cout << "LOOP" << endl;
	    }
		else cout << y << ' ' << x << endl;
	}
	
	return 0;
}

C++: #include <stdio.h>

int main(void){	
	int x, y;
	int w, h;
	int loop;
	char tile[101][101];


	while(1){
		x = 0;
		y = 0;
		loop = 0;

		for(int i=0; i<101; i++){
			for(int j=0; j<101; j++){
				tile[i][j] = 0;
			}
		}

		scanf("%d %d", &w, &h);
		if(w == 0 && h == 0) break;
		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				scanf(" %1c", &tile[j][i]);
			}
		}

		while(1){
			char c = tile[x][y];
			tile[x][y] = 'x';

			if(c == '>') x++;
			else if(c == '<') x--;
			else if(c == '^') y--;
			else if(c == 'v') y++;
			else if(c == '.') break;
			else{
				loop = 1;
				break;
			}
		}
		if(loop == 0)printf("%d %d\n", x, y);
		else printf("LOOP\n");
	}
	return 0;
}