alexjercan/bugnet huggingface dataset:
Problem p00104 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int x, y, d, HW, H, W;
string input[100];
bool orLoop[100][100];

bool loop(int a, int b) {
  if (orLoop[b][a]) {
    return true;
  }
  char i = input[b][a];
  if (i == '>') {
    orLoop[b][a] = true;
    if (loop(a + 1, b)) {
      return true;
    } else
      return false;
  } else if (i == 'v') {
    orLoop[b][a] = true;
    if (loop(a, b + 1)) {
      return true;
    } else
      return false;
  } else if (i == '<') {
    orLoop[b][a] = true;
    if (loop(a - 1, b)) {
      return true;
    } else
      return false;
  } else if (i == '^') {
    orLoop[b][a] = true;
    if (loop(a, b - 1)) {
      return true;
    } else
      return false;
  } else {
    x = a;
    y = b;
    return false;
  }
}

int main() {
  while (cin >> H >> W) {
    if (H == 0 && W == 0) {
      break;
    } else {
      HW = H * W + 2;
    }

    for (int i = 0; i < 100; i++) {
      for (int j = 0; j < 100; j++) {
        orLoop[i][j] = false;
      }
    }
    for (int i = 0; i < H; i++) {
      cin >> input[i];
    }
    if (loop(0, 0)) {
      cout << "LOOP" << endl;
    } else {
      cout << x << " " << y << endl;
    }
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int x, y, d, HW, H, W;
string input[10];
bool orLoop[10][10];

bool loop(int a, int b) {
  if (orLoop[b][a]) {
    return true;
  }
  char i = input[b][a];
  if (i == '>') {
    orLoop[b][a] = true;
    loop(a + 1, b);
  } else if (i == 'v') {
    orLoop[b][a] = true;
    loop(a, b + 1);
  } else if (i == '<') {
    orLoop[b][a] = true;
    loop(a - 1, b);
  } else if (i == '^') {
    orLoop[b][a] = true;
    loop(a, b - 1);
  } else {
    x = a;
    y = b;
    return false;
  }
}

int main() {
  while (cin >> H >> W) {
    if (H == 0 && W == 0) {
      break;
    } else {
      HW = H * W + 2;
    }

    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        orLoop[i][j] = false;
      }
    }
    for (int i = 0; i < H; i++) {
      cin >> input[i];
    }
    if (loop(0, 0)) {
      cout << "LOOP" << endl;
    } else {
      cout << x << " " << y << endl;
    }
  }
  return 0;
}
Problem p00104 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int w, h;
  int i, j;
  while (1) {
    cin >> h;
    cin >> w;
    if (w == 0 || h == 0)
      break;
    vector<vector<char>> v(101, vector<char>(101));
    for (j = 0; j < h; ++j) {
      for (i = 0; i < w; ++i) {
        cin >> v[i][j];
      }
    }
    int mi = 0, mj = 0;
    while (true) {
      char c = v[mi][mj];
      v[mi][mj] = '#';
      if (c == '>')
        mi++;
      else if (c == '<')
        mi--;
      else if (c == '^')
        mj--;
      else if (c == 'v')
        mj++;
      else if (c == '#') {
        cout << "LOOP" << endl;
        break;
      } else if (c == '.') {
        cout << mi << ' ' << mj << endl;
        break;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int w, h;
  int i, j;
  while (1) {
    cin >> w;
    cin >> h;
    if (w == 0 || h == 0)
      break;
    vector<vector<char>> v(h, vector<char>(w));
    for (j = 0; j < h; ++j) {
      for (i = 0; i < w; ++i) {
        cin >> v[i][j];
      }
    }
    int mi = 0, mj = 0;
    while (true) {
      char c = v[mi][mj];
      v[mi][mj] = '#';
      if (c == '>')
        mi++;
      else if (c == '<')
        mi--;
      else if (c == '^')
        mj--;
      else if (c == 'v')
        mj++;
      else if (c == '#') {
        cout << "LOOP" << endl;
        break;
      } else if (c == '.') {
        cout << mi << ' ' << mj << endl;
        break;
      }
    }
  }
  return 0;
}
Problem p00104 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;

int main() {
  int w, h;
  string m[110];
  bool f[110][110], flag;

  while (cin >> h >> w, w, h) {
    flag = false;
    for (int y = 0; y < h; y++) {
      m[y].clear();
      for (int x = 0; x < w; x++) {
        f[y][x] = false;
      }
    }
    for (int y = 0; y < h; y++) {
      cin >> m[y];
    }
    int x = 0, y = 0;
    while (1) {
      if (m[y][x] == '>')
        x++;
      if (m[y][x] == '<')
        x--;
      if (m[y][x] == 'v')
        y++;
      if (m[y][x] == '^')
        y--;

      if (m[y][x] == '.' || f[y][x]) {
        if (f[y][x])
          flag = true;
        break;
      }
      f[y][x] = true;
    }
    (flag) ? (cout << "LOOP" << endl) : (cout << x << " " << y << endl);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;

int main() {
  string map[110];
  int w, h;
  bool f[110][110], flag;

  while (cin >> w >> h, w, h) {
    for (int i = 0; i < 110; i++) {
      map[i].clear();
    }
    for (int y = 0; y < 110; y++) {
      for (int x = 0; x < 110; x++) {
        f[y][x] = false;
      }
    }
    flag = false;

    for (int i = 0; i < h; i++) {
      cin >> map[i];
    }
    int x = 0, y = 0;
    while (map[y][x] != '.') {
      f[y][x] = true;
      if (map[y][x] == '>') {
        x++;
      } else if (map[y][x] == '<') {
        x--;
      } else if (map[y][x] == 'v') {
        y++;
      } else if (map[y][x] == '^') {
        y--;
      }

      if (f[y][x]) {
        flag = true;
        break;
      }
    }
    (flag) ? cout << "LOOP" << endl : cout << x << y << endl;
  }

  return 0;
}
Problem p00104 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define H_MAX 100
#define W_MAX 100

int H, W;

string f[H_MAX];      // field
bool p[H_MAX][W_MAX]; // have passed?

void go(int x, int y) {
  if (p[y][x]) {
    cout << "LOOP\\n";
    return;
  }
  p[y][x] = true;
  switch (f[y][x]) {
  case '>':
    go(x + 1, y);
    break;
  case '<':
    go(x - 1, y);
    break;
  case '^':
    go(x, y - 1);
    break;
  case 'v':
    go(x, y + 1);
    break;
  default:
    cout << x << ' ' << y << endl;
    break;
  }
}

int main() {
  while (cin >> H >> W) {
    if (H == 0 && W == 0)
      break;
    for (int i = 0; i < H; i++) {
      cin >> f[i];
      for (int j = 0; j < W; j++) {
        p[i][j] = false;
      }
    }
    go(0, 0);
  }
  return 0;
}

Error: WA

Fixed submission:


#include <iostream>
#include <istream>
#include <ostream>

class Tiles {
  char **dir;
  bool **visited;
  int pos_x, pos_y;
  int h, w;

public:
  Tiles(std::istream &is) {
    is >> h >> w;
    if (h == 0 && w == 0) {
      return;
    }
    dir = new char *[h];
    visited = new bool *[h];
    for (int i = 0; i < w; i++) {
      dir[i] = new char[w];
      visited[i] = new bool[w];
    }
    pos_x = pos_y = 0;

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

  void solve() {
    if (visited[pos_y][pos_x]) {
      std::cout << "LOOP" << std::endl;
      return;
    }
    if (dir[pos_y][pos_x] == '.') {
      std::cout << pos_x << ' ' << pos_y << std::endl;
    } else {
      visited[pos_y][pos_x] = true;
      switch (dir[pos_y][pos_x]) {
      case '>':
        pos_x++;
        break;
      case '<':
        pos_x--;
        break;
      case 'v':
        pos_y++;
        break;
      case '^':
        pos_y--;
        break;
      }
      solve();
    }
  }

  bool is_empty() { return (h == 0 && w == 0); }
};

int main() {
  Tiles *t;
  while (true) {
    t = new Tiles(std::cin);
    if (t->is_empty())
      break;
    t->solve();
  }
  return 0;
}
Problem p00104 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstring>
#include <iostream>
using namespace std;
char a[8000][8000];
int h, w, loop, cx, cy;
int main() {
  while (true) {
    cin >> h >> w;
    if (!h) {
      break;
    }
    memset(a, ' ', sizeof(a));
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> a[i][j];
      }
    }
    cx = 0;
    cy = 0;
    loop = 0;
    while (true) {
      if (loop > 15000000) {
        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') {
        cy++;
      }
      loop++;
    }
  }
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
char a[8000][8000];
int h, w, loop, cx, cy;
int main() {
  while (true) {
    cin >> h >> w;
    if (!h) {
      break;
    }
    memset(a, ' ', sizeof(a));
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> a[i][j];
      }
    }
    cx = 0;
    cy = 0;
    loop = 0;
    while (true) {
      if (loop > 18000000) {
        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') {
        cy++;
      }
      loop++;
    }
  }
}
Problem p00104 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
#include <string.h>

int main() {
  char ss[2][110][111];
  int w, h, i, x, y, loop;

  while (~scanf("%d%d", &w, &h)) {
    if (w == 0 && h == 0)
      break;

    memset(ss, 0, sizeof(ss));

    for (i = 0; i < w; i++) {
      scanf(" %s ", ss[0][i]);
    }

    x = 0;
    y = 0;
    loop = 0;
    ss[1][y][x] = 1;
    while (1) {
      switch (ss[0][y][x]) {
      case '>':
        ++x;
        loop = ss[1][y][x];
        ss[1][y][x] = 1;
        break;
      case '<':
        --x;
        loop = ss[1][y][x];
        ss[1][y][x] = 1;
        break;
      case '^':
        --y;
        loop = ss[1][y][x];
        ss[1][y][x] = 1;
        break;
      case 'v':
        ++y;
        loop = ss[1][y][x];
        ss[1][y][x] = 1;
        break;
      }

      if (loop)
        break;
      if (ss[0][y][x] == '.')
        break;
    }

    if (loop == 1) {
      printf("LOOP\\n");
    } else {
      printf("%d %d\\n", x, y);
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#include <string.h>

int main() {
  char ss[2][110][111];
  int w, h, i, j, x, y, loop;

  while (~scanf("%d%d", &w, &h)) {
    if (w == 0 && h == 0)
      break;

    memset(ss, 0, sizeof(ss));

    for (i = 0; i < h; i++) {
      scanf(" %s ", ss[0][i]);
    }

    x = 0;
    y = 0;
    loop = 0;

    while (1) {
      switch (ss[0][y][x]) {
      case '>':
        ++x;
        loop = ss[1][y][x];
        ss[1][y][x] = 1;
        break;
      case '<':
        --x;
        loop = ss[1][y][x];
        ss[1][y][x] = 1;
        break;
      case '^':
        --y;
        loop = ss[1][y][x];
        ss[1][y][x] = 1;
        break;
      case 'v':
        ++y;
        loop = ss[1][y][x];
        ss[1][y][x] = 1;
        break;
      }

      if (loop)
        break;
      if (ss[0][y][x] == '.')
        break;
    }

    if (loop == 1) {
      printf("LOOP\\n");
    } else {
      printf("%d %d\\n", x, y);
    }
  }
  return 0;
}
Problem p00104 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:

#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 << i << " " << j << 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;
}
Problem p00104 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int w, h, x, y;
  char tile[100][100];
  bool use[100][100];
  bool flg;

  while (1) {
    cin >> h >> w;
    if (w == 0 && h == 0) {
      break;
    }
    for (y = 0; y < h; y++) {
      for (x = 0; x < w; x++) {
        cin >> tile[x][y];
        use[x][y] = false;
      }
    }

    x = 0;
    y = 0;
    flg = true;
    do {
      if (use[x][y]) {
        cout << "LOOP" << endl;
        break;
      }
      use[x][y] = true;
      switch (tile[x][y]) {
      case '.':
        flg = false;
        cout << x << " " << y << endl;
        break;

      case '>':
        x += 1;
        break;

      case '<':
        x -= 1;
        break;

      case '^':
        y -= 1;
        break;

      case 'v':
        y += 1;
        break;
      }
    } while (flg);
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int w, h, x, y;
  char tile[100][100];
  bool use[100][100];
  bool flg;

  while (1) {
    cin >> w >> h;
    for (y = 0; y < h; y++) {
      for (x = 0; x < w; x++) {
        cin >> tile[x][y];
        use[x][y] = false;
      }
    }

    x = 0;
    y = 0;
    flg = false;
    do {
      if (use[x][y]) {
        cout << "LOOP" << endl;
        break;
      }
      use[x][y] = true;
      switch (tile[x][y]) {
      case '.':
        flg = true;
        cout << x << " " << y;
        break;

      case '>':
        x += 1;
        break;

      case '<':
        x -= 1;
        break;

      case '^':
        y -= 1;
        break;

      case 'v':
        y += 1;
        break;
      }
    } while (flg);
  }
}
Problem p00104 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

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

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#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;
}
Problem p00104 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;

//// < "D:\\D_Download\\Visual Studio
///2015\\Projects\\programing_contest_c++\\Debug\\a.txt"
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  map<char, int> mp;
  mp['<'] = 0;
  mp['v'] = 1;
  mp['>'] = 2;
  mp['^'] = 3;
  mp['.'] = 4;
  while (1) {
    int H, W;
    cin >> H >> W;
    if (!H)
      break;
    vector<vector<int>> field(H, vector<int>(W));
    for (int i = 0; i < H; ++i) {
      string st;
      cin >> st;
      for (int j = 0; j < W; ++j) {
        field[i][j] = mp[st[j]];
      }
    }
    int nx = 0;
    int ny = 0;
    for (int i = 0; i < 20000; ++i) {
      if (i == 19999) {
        nx = -1;
        break;
      }
      int a = field[ny][nx];
      if (a == 4) {
        break;
      } else {
        nx += dx[a];
        ny += dy[a];
      }
    }
    if (nx == -1) {
      cout << "LOOP" << endl;
    } else {
      cout << nx << " " << ny << endl;
    }
  }

  return 0;
}

Error: -11

Fixed submission:

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;

//// < "D:\\D_Download\\Visual Studio
///2015\\Projects\\programing_contest_c++\\Debug\\a.txt"
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  map<char, int> mp;
  mp['<'] = 0;
  mp['v'] = 1;
  mp['>'] = 2;
  mp['^'] = 3;
  mp['.'] = 4;
  while (1) {
    int H, W;
    cin >> H >> W;
    if (!H)
      break;
    vector<vector<int>> field(H, vector<int>(W));
    for (int i = 0; i < H; ++i) {
      string st;
      cin >> st;
      for (int j = 0; j < W; ++j) {
        field[i][j] = mp[st[j]];
      }
    }
    int nx = 0;
    int ny = 0;
    for (int i = 0; i < 20000; ++i) {
      if (i == 19999) {
        nx = -1;
        break;
      }
      if (field[ny][nx] == 4) {
        break;
      } else {
        nx += dx[field[ny][nx]];
        ny += dy[field[ny][nx]];
      }
    }
    if (nx == -1) {
      cout << "LOOP" << endl;
    } else {
      cout << nx << " " << ny << endl;
    }
  }

  return 0;
}
Problem p00104 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>

using namespace std;

char tile[101][101];

void loop(int x, int y) {
  if (tile[x][y] == '.') {
    cout << y << ' ' << x << endl;
    return;
  }
  if (tile[x][y] == '#') {
    cout << "LOOP" << endl;
    return;
  }
  if (tile[x][y] == '>') {
    tile[x][y] = '#';
    loop(x, y + 1);
  }
  if (tile[x][y] == '<') {
    tile[x][y] = '#';
    loop(x, y - 1);
  }
  if (tile[x][y] == '^') {
    tile[x][y] = '#';
    loop(x - 1, y);
  }
  if (tile[x][y] == 'v') {
    tile[x][y] = '#';
    loop(x + 1, y);
  }
}

int main(void) {
  int h, w;
  int x, y;
  int a;
  while (1) {
    x = 0, y = 0;
    cin >> h >> w;
    if (h == 0 && w == 0)
      break;
    for (a = 0; a < h; a++) {
      cin >> tile[a];
    }
    loop(0, 0);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>

using namespace std;

char tile[11][11];

void loop(int x, int y) {
  if (tile[x][y] == '.') {
    cout << y << ' ' << x << endl;
    return;
  }
  if (tile[x][y] == '#') {
    cout << "LOOP" << endl;
    return;
  }
  if (tile[x][y] == '>') {
    tile[x][y] = '#';
    loop(x, y + 1);
  }
  if (tile[x][y] == '<') {
    tile[x][y] = '#';
    loop(x, y - 1);
  }
  if (tile[x][y] == '^') {
    tile[x][y] = '#';
    loop(x - 1, y);
  }
  if (tile[x][y] == 'v') {
    tile[x][y] = '#';
    loop(x + 1, y);
  }
}

int main(void) {
  int h, w;
  int x, y;
  int a;
  while (1) {
    x = 0, y = 0;
    cin >> h >> w;
    if (h == 0 && w == 0)
      break;
    for (a = 0; a < h; a++) {
      cin >> tile[a];
    }
    loop(0, 0);
  }
  return 0;
}
Problem p00104 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string.h>
using namespace std;

struct zahyou {
  int x;
  int y;
};

int main() {

  int tx, ty, count;
  char map[100][100];
  bool flag;
  struct zahyou now;

  while (cin >> tx >> ty, tx && ty) {

    flag = false;
    now.x = 0;
    now.y = 0;
    memset(map, '\\0', sizeof(map));

    for (int i = 0; i < tx; i++) {
      for (int j = 0; j < ty; j++) {
        cin >> map[i][j];
      }
    }

    while (1) {

      if (map[now.y][now.x] == '.') {
        cout << now.x << " " << now.y << endl;
        break;
      } else if (map[now.y][now.x] == '1') {
        cout << "LOOP" << endl;
        break;
      }

      if (map[now.y][now.x] == '>') {
        map[now.y][now.x] = '1';
        now.x++;
      } else if (map[now.y][now.x] == '<') {
        map[now.y][now.x] = '1';
        now.x--;
      } else if (map[now.y][now.x] == 'v') {
        map[now.y][now.x] = '1';
        now.y++;
      } else if (map[now.y][now.x] == '^') {
        map[now.y][now.x] = '1';
        now.y--;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string.h>
using namespace std;

struct zahyou {
  int x;
  int y;
};

int main() {

  int tx, ty, count;
  char map[100][100];
  bool flag;
  struct zahyou now;

  while (cin >> tx >> ty, tx && ty) {

    flag = false;
    now.x = 0;
    now.y = 0;
    memset(map, '\\0', sizeof(map));

    for (int i = 0; i < ty; i++) {
      for (int j = 0; j < tx; j++) {
        cin >> map[i][j];
      }
    }

    while (1) {

      if (map[now.y][now.x] == '.') {
        cout << now.x << " " << now.y << endl;
        break;
      } else if (map[now.y][now.x] == '1') {
        cout << "LOOP" << endl;
        break;
      }

      if (map[now.y][now.x] == '>') {
        map[now.y][now.x] = '1';
        now.x++;
      } else if (map[now.y][now.x] == '<') {
        map[now.y][now.x] = '1';
        now.x--;
      } else if (map[now.y][now.x] == 'v') {
        map[now.y][now.x] = '1';
        now.y++;
      } else if (map[now.y][now.x] == '^') {
        map[now.y][now.x] = '1';
        now.y--;
      }
    }
  }
}