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>
#include<algorithm>
#include<vector>
#include<iostream>
using namespace std;
int W,H;
char fie[102][102];
int cost[102][102];
char df[]={'>','v','<','^'};
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int main(){
  while(1){
    cin >> H >> W;
    memset(fie,-1,sizeof(fie));
    memset(cost,0,sizeof(cost));
    if(W==0 && H==0) break;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	cin >> fie[j][i];
      }
    }
    int x=0,y=0;
    bool f=false;
    cost[x][y]=1;
    while(fie[x][y]!='.'){
      for(int i=0;i<4;i++){
	
	if(fie[x][y]==df[i]){
	  x+=dx[i];
	  y+=dy[i];
	}
      }
      if(cost[x][y]){
	f=true;
	break;
      }
      cost[x][y]=1;
    }
    if(!f) printf("%d %d\n",x,y);
    else puts("LOOP");
  }
}

C++: #include <iostream>
#include <string>
using namespace std;
bool Istraveled[100][100];
char data[100][100];

void solve(int h,int w) {
	Istraveled[h][w]=true;
	char x=data[h][w];
	if(x=='.') {
		cout<<w<<" "<<h<<endl;
	}
	else if(x=='^') {
		if(Istraveled[h-1][w]==true) {
			cout<<"LOOP"<<endl;
		}
		else {
			solve(h-1,w);
		}
	}
	else if(x=='v') {
		if(Istraveled[h+1][w]==true) {
			cout<<"LOOP"<<endl;
		}
		else {
			solve(h+1,w);
		}
	}
	else if(x=='>') {
		if(Istraveled[h][w+1]==true) {
			cout<<"LOOP"<<endl;
		}
		else {
			solve(h,w+1);
		}
	}
	else if(x=='<') {
		if(Istraveled[h][w-1]==true) {
			cout<<"LOOP"<<endl;
		}
		else {
			solve(h,w-1);
		}
	}
}

int main(void) {
	int h,w;
	string in;
	while(cin>>h>>w,h) {
		for(int i=0;i<h;i++) {
			cin>>in;
			for(int j=0;j<w;j++) {
				data[i][j]=in[j];
				Istraveled[i][j]=false;
			}
		}
		solve(0,0);
	}
	return 0;
}

C++: #include<iostream>

std::pair<char,bool> data[101][101];

int main(){
	int w,h;
	std::cin>>w>>h;
	while(w!=0&&h!=0){
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				std::cin>>data[i][j].first;
				data[i][j].second=false;
			}
		}
		int x=0,y=0;
		while(true){
			if(data[y][x].second){
				std::cout<<"LOOP"<<std::endl;
				break;
			}else data[y][x].second=true;

			if(data[y][x].first=='^')y-=1;
			else if(data[y][x].first=='>')x+=1;
			else if(data[y][x].first=='v')y+=1;
			else if(data[y][x].first=='<')x-=1;

			if(data[y][x].first=='.'){
				std::cout<<x<<" "<<y<<std::endl;
				break;
			}
		}
		std::cin>>w>>h;
	}
	return 0;
}

C++: #include <iostream>
#include <complex>
#include <map>

using namespace std;

typedef complex<int> P;

int main() {
	P dirs[5] = {
		P(0, 0),
		P(0, -1),
		P(1, 0),
		P(0, 1),
		P(-1, 0)
	};
	map<char, int> trans;
	trans['.'] = 0;
	trans['^'] = 1;
	trans['>'] = 2;
	trans['v'] = 3;
	trans['<'] = 4;

	int W, H;
	int m[100][100];
	while (cin >> H >> W, H || W) {
		for (int y = 0; y < H; ++y) {
			string str; cin >> str;
			for (int x = 0; x < W; ++x)
				m[y][x] = trans[str[x]];
		}

		P p = P(0, 0);
		for (int i = 0; i < W*H; ++i)
			p += dirs[m[p.imag()][p.real()]];

		if (m[p.imag()][p.real()]) cout << "LOOP" << endl;
		else cout << p.real() << " " << p.imag() << endl;
	}
}

C++: #include<iostream>
using namespace std;
int main(){
  int H,W,x,y;
  while(cin>>H>>W){
    if(H==0&&W==0) break;
    char space[H][W],c;
    for(int i=0;i<W;i++){
      for(int j=0;j<H;j++){
	cin >> space[j][i];
      }
    }
    x = y = 0;
    while(1){
      c = space[x][y];
      space[x][y] = '0';
      if(c=='>') x++;
      else if(c=='<') x--;
      else if(c=='v') y++;
      else if(c=='^') y--;
      else if(c=='.'){
	cout << x << ' ' << y << endl;
	break;
      }
      else if(c=='0'){
	cout << "LOOP" << endl;
	break;
      }
    }
  }
  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <functional>

using namespace std;

#define rep(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(itr,c) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

int H,W;
char field[110][110];
map<char,int> dx;
map<char,int> dy;

void make(){
  dx['^'] = 0;  dy['^'] = -1;
  dx['v'] = 0;  dy['v'] = 1;
  dx['>'] = 1;  dy['>'] = 0;
  dx['<'] = -1; dy['<'] = 0;
}

pair<int,int> func(int i, int j){
  if(field[i][j] == '.') return make_pair(i,j);
  int cnt = 0;

  while(1){
    if(i < 0 || j < 0 || i >= H || j >= W) continue;
    cnt++;
    i += dy[field[i][j]];
    j += dx[field[i][j]];
    if(field[i][j] == '.') return make_pair(i,j);
    if(cnt > 10000) break;
  }

  return make_pair(-1,-1);
}

int main(){
  int i,j,k;

  make();
  for(; ~scanf("%d %d",&H,&W); ){
    if(H == 0 && W == 0) break;

    rep(i,H) scanf("%s",&field[i]);

    pair<int,int> res = func(0,0), out(-1,-1);
    if(res == out) puts("loop");
    else printf("%d %d\n",res.second,res.first);
  }

  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <vector>
#include <algorithm>

#define int64 long long int
#define RIGHT 1
#define UP 2
#define LEFT 3
#define DOWN 4
#define CLEARED 5

using namespace std;

int main()
{
	int H, W, x, y;
	int map[101][101];
	string buf;
	while(1){
		cin >> H >> W;
		if(H == 0) break;

		memset(map, 0, sizeof(int)*101*101);

		for(int i=0; i<H; i++){
			cin >> buf;
			for(int j=0; j<W; j++){
				if(buf[j] == '>') map[i][j] = RIGHT;
				else if(buf[j] == '^') map[i][j] = UP;
				else if(buf[j] == '<') map[i][j] = LEFT;
				else if(buf[j] == 'v') map[i][j] = DOWN;
			}
		}

		x = 0, y = 0;

		while(1){
			if(map[y][x] == CLEARED){
				cout << "LOOP" << endl;
				break;
			} else if(map[y][x] == RIGHT){
				map[y][x] = CLEARED;
				x++;
			} else if(map[y][x] == UP){
				map[y][x] = CLEARED;
				y--;
			} else if(map[y][x] == LEFT){
				map[y][x] = CLEARED;
				x--;
			} else if(map[y][x] == DOWN){
				map[y][x] = CLEARED;
				y++;
			} else {
				cout << x << ' ' << y << endl;
				break;
			}
		}
	}
	return 0;
}

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

int main(){
   int a, b, i, j;
   char map[102][102];
   
   while(1){
      cin >> a >> b;
      if(a+b==0) break;
      
      for(i=0; i< a; i++){
         for(j=0; j< b; j++){
            cin >> map[i][j];
         }
      }
      i=0,j=0;
      while(1){
         if(map[i][j]=='.'){
            cout << j << " " << i << endl;
            break;
         }else if(map[i][j]=='#'){
            cout << "loop" << endl;
            break;
         }else if(map[i][j]=='>'){
            map[i][j]='#';
            j++;
         }else if(map[i][j]=='<'){
            map[i][j]='#';
            j--;
         }else if(map[i][j]=='^'){
            map[i][j]='#';
            i--;
         }else if(map[i][j]=='v'){
            map[i][j]='#';
            i++;
         }
      }
   }
   return 0;
}