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

int main(void) {
  int H, W;
  while (cin >> H >> W, H || W) {
    vector<vector<char> > tiles(H, vector<char>(W));

    for (auto i = 0; i < H; i++) {
      for (auto j = 0; j < W; j++) {
        cin >> tiles[i][j];
      }
    }

    bool flag = true;
    int nowX = 0, nowY = 0;
    int max_num = H * W + 1;
    while (flag && max_num--) {
      switch(tiles[nowY][nowX]) {
      case '>':
        nowX++;
        break;
      case '<':
        nowX--;
        break;
      case '^':
        nowY--;
        break;
      case 'v':
        nowY++;
        break;
      default:
        flag = false;
        break;
      }
    }

    if (max_num > 0) {
      cout << nowX << " " << nowY << endl;
    } else {
      cout << "LOOP" << endl;
    }
  }
  return 0;
}

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

int main(int argc, char const* argv[])
{
	unsigned h{}, w{};
	while (std::cin >> h >> w, h != 0) {
		std::vector<char> tiles{};
		std::vector<bool> walked{};
		auto mapsize = h * w;
		tiles.reserve(mapsize);
		walked.assign(mapsize, false);
		for (int i = 0; i < mapsize; i++) {
			char c;
			std::cin >> c;
			tiles.push_back(c);
		}
		//walk
		unsigned current{};
		bool end{false}, loop{false};
		while ( !(end || loop) ) {
			switch (tiles.at(current)) {
				case '>':
					current += 1;
					break;
				case '<':
					current -= 1;
					break;
				case 'v':
					current += w;
					break;
				case '^':
					current -= w;
					break;
				case '.':
					end = true;
					break;
				default:
					break;
			}
			if (walked.at(current) && !end) {
				loop = true;
				break;
			}
			walked.at(current) = true;
		}
		if (loop) {
			std::cout << "LOOP" << std::endl;
		} else {
			auto x = current % w;
			auto y = current / w;
			std::cout << x << ' ' << y << std::endl;
		}
	}


	return 0;
}

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


int main()
{
	int w,k,hyou[101][101],i,j,checki[101],check[101],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 <vector>
#include <set>
using namespace std;
int main(){
	for(int w,h;cin>>w>>h;){
		if(w==0&&h==0)break;
		vector<string> v;
		set<int> visited;
		for(int i=0;i<h;++i){
			string s;
			cin>>s;
			v.push_back(s);
		}
		for(int x=0,y=0;;){
			if(visited.find(y*w+x)!=visited.end()){
				cout<<"LOOP\n";
				break;
			}
			visited.insert(y*w+x);
			if(v[y][x]=='.'){
				cout<<x<<" "<<y<<"\n";
				break;
			}else if(v[y][x]=='>')++x;
			else if(v[y][x]=='<')--x;
			else if(v[y][x]=='v')++y;
			else if(v[y][x]=='^')--y;
		}
	}
}

C++: #include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int h,w;
string ss[100];
bool x[100][100];
int ans1=0,ans2=0;
bool ans=true;
bool f(){
	while(true){
		if(ss[ans1][ans2]=='.')return true;
		else if(!x[ans1][ans2])return false;
		else if(ss[ans1][ans2]=='>'){
			x[ans1][ans2]=false;
			ans2++;
			f();
		}
		else if(ss[ans1][ans2]=='<'){
			x[ans1][ans2]=false;
			ans2--;
			f();
		}
		else if(ss[ans1][ans2]=='v'){
			x[ans1][ans2]=false;
			ans1++;
			f();
		}
		else{
			x[ans1][ans2]=false;
			ans1--;
			f();
		}
	}
}
int main()
{
	while(true){
		scanf("%d%d",&h,&w);
		if(h==0&&w==0)return 0;
		for(int i=0;i<h;i++)cin >> ss[i];
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)x[i][j]=true;
		ans1=0,ans2=0;
		ans=true;

		if(f()){
		    cout << ans2 << " " << ans1 << "\n";
		}
		else cout << "LOOP" << "\n";
	}
	return 0;
}

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

#define RIGHT '>'
#define LEFT '<'
#define TOP '^'
#define UNDER 'v'
#define END '.'
#define LOOP 'l'
#define MAX 101

void dfs(char mp[MAX][MAX],int i,int j){
    if(mp[i][j] == END){
        cout << i << ' ' << j << endl;
        return;
    }
    if(mp[i][j] == LOOP){
        cout << "LOOP" << endl;
        return ;
    }
    mp[i][j] = LOOP;
    if(mp[i][j] == RIGHT) dfs(mp,i,j+1);
    else if(mp[i][j] == LEFT) dfs(mp,i,j-1);
    else if(mp[i][j] == TOP) dfs(mp,i-1,j);
    else if(mp[i][j] == UNDER) dfs(mp,i+1,j);
}

int main(){
    char mp[MAX][MAX];
    int n,m;
    
    while(true){
        cin >> n >> m;
        if(!n&&!m) break;
        
        for(int i = 0 ; i < n ; i++)
            for(int j = 0 ; j < m ; j++)
                cin >> mp[i][j];
        
        dfs(mp,0,0);
    }
    
    return 0;
}

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

int main()
{
  while(true)
  {
    int h,w;
    cin >> h >> w;
    if ( h == 0 && w == 0 ) break;
    char **room = new char*[h];
    for (int i=0; i<h; i++)
    {
      room[i] = new char[w];
    }

    for (int i=0; i<h; i++)
    {
      for (int j=0; j<w; j++)
      {
        cin >> room[i][j];
      }
    }

    int x = 0;
    int y = 0;
    bool flag = true;
    while(flag)
    {
      switch (room[y][x])
      {
      case '>':
        room[y][x] = 'x';
        x++;
        break;
      case '<':
        room[y][x] = 'x';
        x--;
        break;
      case '^':
        room[y][x] = 'x';
        y--;
        break;
      case 'v':
        room[y][x] = 'x';
        y++;
        break;
      case '.':
        cout << x << ' ' << y << endl;
        flag = false;
        break;
      case 'x':
        cout << "LOOP" << endl;
        flag = false;
        break;
      }
    } //おへや

    for (int i=0; i<h; i++)
    {
      delete[] room[i];
    }
    delete[] room;
  } //  データセット
}