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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  string s;
  string soro[10] = {"* = ****", "* =* ***", "* =** **", "* =*** *",
                     "* =**** ", " *= ****", " *=* ***", " *=** **",
                     " *=*** *", " *=**** "};
  bool flag = true;
  while (cin >> s) {
    vector<char> c;
    for (int i = 0; i < 5 - s.size(); i++) {
      c.push_back('0');
    }
    for (int i = 0; i < s.size(); i++) {
      c.push_back(s[i]);
    }
    if (flag) {
      flag = false;
    } else {
      cout << endl;
    }

    for (int i = 0; i < 8; i++) {
      for (int j = 0; j < 5; j++) {
        cout << soro[c[j] - '0'][i];
      }
      cout << endl;
    }
  }
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  string s;
  string soro[10] = {"* = ****", "* =* ***", "* =** **", "* =*** *",
                     "* =**** ", " *= ****", " *=* ***", " *=** **",
                     " *=*** *", " *=**** "};
  bool flag = true;
  while (cin >> s) {
    vector<char> c;
    for (int i = 0; i < s.size(); i++) {
      c.push_back('0');
    }
    for (int i = 0; i < s.size(); i++) {
      c.push_back(s[i]);
    }
    if (flag) {
      flag = false;
    } else {
      cout << endl;
    }

    for (int i = 0; i < 8; i++) {
      for (int j = 0; j < 5; j++) {
        cout << soro[c[j] - '0'][i];
      }
      cout << endl;
    }
  }
  return 0;
}
Problem p00128 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  bool f = false;
  int n, i, j;
  int a[6];
  char a0[11][10] = {"* = ****", "* =* ***", "* =** **", "* =*** *",
                     "* =**** ", " *= ****", " *=* ***", " *=** **",
                     " *=*** *", " *=**** "};
  while (cin >> n) {
    if (f == true) {
      cout << endl;
    }
    a[0] = n / 10000;
    a[1] = (n - a[0] * 10000) / 1000;
    a[2] = (n - a[0] * 10000 - a[1] * 1000) / 100;
    a[3] = (n - a[0] * 10000 - a[1] * 1000 - a[2] * 100) / 10;
    a[4] = (n - a[0] * 10000 - a[1] * 1000 - a[2] * 100 - a[3] * 10);
    for (i = 0; i < 8; i++) {
      for (j = 0; j < 5; j++) {
        cout << a0[a[j]][i];
      }
      cout << endl;
    }
    f = true;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  bool f = false;
  int n, i, j;
  int a[6];
  char a0[11][10] = {"* = ****", "* =* ***", "* =** **", "* =*** *",
                     "* =**** ", " *= ****", " *=* ***", " *=** **",
                     " *=*** *", " *=**** "};
  cin >> n;
  while (n != 'EOF') {
    if (f == true)
      cout << endl;
    a[0] = n / 10000;
    a[1] = (n - a[0] * 10000) / 1000;
    a[2] = (n - a[0] * 10000 - a[1] * 1000) / 100;
    a[3] = (n - a[0] * 10000 - a[1] * 1000 - a[2] * 100) / 10;
    a[4] = (n - a[0] * 10000 - a[1] * 1000 - a[2] * 100 - a[3] * 10);
    for (i = 0; i < 8; i++) {
      for (j = 0; j < 5; j++) {
        cout << a0[a[j]][i];
      }
      cout << endl;
    }
    f = true;
    cin >> n;
  }
  return 0;
}
Problem p00128 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)
#define rreps(v, f, l) for (int v = (l), v##_ = (f); v >= v##_; --v)
#define rrep(v, n) rreps(v, 0, n - 1)
#define rlep(v, n) rreps(v, 1, n)
#define show_a(a, size)                                                        \\
  rep(a##_it, size) std::cout << a[a##_it] << " \\n"[a##_it == a##_it_ - 1];
#define show_v(v) show_a(v, v.size())
#define debug(x) std::cerr << #x << " = " << (x) << "\\n";

using namespace std;

typedef long long int lint;

static inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
static inline lint inl() {
  lint x;
  scanf("%lld", &x);
  return x;
}

int main() {
  bool is_first = true;
  int n;
  while (~scanf("%d", &n)) {
    if (is_first)
      is_first = false;
    else
      puts("");
    char snum[8];
    sprintf(snum, "%05d", n);
    rep(i, 5) printf("%c", " *"[snum[i] < '5']);
    puts("");
    rep(i, 5) printf("%c", "* "[snum[i] < '5']);
    puts("");
    puts("=====");
    rep(i, 5) {
      rep(j, 5) { printf("%c", " *"[i != (snum[j] - '0') % 5]); }
      puts("");
    }
  }
  return (0);
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)
#define rreps(v, f, l) for (int v = (l), v##_ = (f); v >= v##_; --v)
#define rrep(v, n) rreps(v, 0, n - 1)
#define rlep(v, n) rreps(v, 1, n)
#define show_a(a, size)                                                        \\
  rep(a##_it, size) std::cout << a[a##_it] << " \\n"[a##_it == a##_it_ - 1];
#define show_v(v) show_a(v, v.size())
#define debug(x) std::cerr << #x << " = " << (x) << "\\n";

using namespace std;

typedef long long int lint;

static inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
static inline lint inl() {
  lint x;
  scanf("%lld", &x);
  return x;
}

int main() {
  bool is_first = true;
  int n;
  while (~scanf("%d", &n)) {
    if (is_first)
      is_first = false;
    else
      puts("");
    char snum[8];
    sprintf(snum, "%05d", n);
    debug(snum);
    rep(i, 5) printf("%c", " *"[snum[i] < '5']);
    puts("");
    rep(i, 5) printf("%c", "* "[snum[i] < '5']);
    puts("");
    puts("=====");
    rep(i, 5) {
      rep(j, 5) { printf("%c", " *"[i != (snum[j] - '0') % 5]); }
      puts("");
    }
  }
  return (0);
}
Problem p00128 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int i, j = 0, n[5];
  string s, l[2] = {" ", "*"};
  char x[6];
  while (cin >> i) {
    if (j)
      cout << endl;
    sprintf(x, "%05d", i);
    for (j = 5; j-- > 0;)
      n[j] = x[j] - '0';
    s = "";
    while (j++ < 1) {
      for (i = 0; i < 5; i++)
        s += l[j + (n[i] < 5) & 1];
      s += "\\n";
    }
    for (j = 5; j-- > 0;)
      s += "=";
    s += "\\n";
    while (j++ < 4) {
      for (i = 0; i < 5; i++)
        s += l[n[i] % 5 != j];
      s += "\\n";
    }
    cout << s;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int i, j = 0, n[5];
  string s;
  char x[5], l[2] = {' ', '*'};
  while (cin >> i) {
    if (j)
      cout << endl;
    sprintf(x, "%05d", i);
    for (j = 5; j-- > 0;)
      n[j] = x[j] - '0';
    s = "";
    while (j++ < 1) {
      for (i = 0; i < 5; i++)
        s += l[j + (n[i] < 5) & 1];
      s += "\\n";
    }
    for (j = 5; j-- > 0;)
      s += "=";
    s += "\\n";
    while (j++ < 4) {
      for (i = 0; i < 5; i++)
        s += l[n[i] % 5 != j];
      s += "\\n";
    }
    cout << s;
  }
  return 0;
}
Problem p00128 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  int pow10[] = {10000, 1000, 100, 10, 1};
  while (!(cin >> n))
    return 0;
  while (1) {
    for (int i = 0; i < 2; i++) {
      for (int j = 0; j < 5; j++) {
        if (i == (5 <= n / pow10[j] % 10))
          cout << '*';
        else
          cout << ' ';
      }
      cout << endl;
    }
    cout << "=====\\n";
    for (int i = 0; i < 5; i++) {
      for (int j = 0; j < 5; j++) {
        if (n / pow10[j] % 5 == i)
          cout << ' ';
        else
          cout << '*';
      }
      cout << endl;
    }
    if (cin >> n)
      cout << endl;
    else
      break;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  int pow10[] = {10000, 1000, 100, 10, 1};
  while (!(cin >> n && n))
    return 0;
  while (1) {
    for (int i = 0; i < 2; i++) {
      for (int j = 0; j < 5; j++) {
        if (i == (5 <= n / pow10[j] % 10))
          cout << '*';
        else
          cout << ' ';
      }
      cout << endl;
    }
    cout << "=====\\n";
    for (int i = 0; i < 5; i++) {
      for (int j = 0; j < 5; j++) {
        if (n / pow10[j] % 5 == i)
          cout << ' ';
        else
          cout << '*';
      }
      cout << endl;
    }
    if (cin >> n && n)
      cout << endl;
  }
  return 0;
}
Problem p00128 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF (1 << 20)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

string str[] = {"* = ****", "* =* ***", "* =** **", "* =*** *", "* =**** ",
                " *= ****", " *=* ***", " *=** **", " *=*** *", " *=**** "};

int main() {
  int cnt = 0;
  string n;

  while (cin >> n) {
    if (cnt++)
      cout << endl;

    while (n.size() < 5)
      n = "0" + n;

    vector<string> s(n.size());
    rep(i, n.size()) s[i] = str[n[i] - '0'];

    rep(i, 8) {
      rep(j, 5) { cout << s[j][i]; }
      cout << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF (1 << 20)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

string str[] = {"* = ****", "* =* ***", "* =** **", "* =*** *", "* =**** ",
                " *= ****", " *=* ***", " *=** **", " *=*** *", "*=**** "};

int main() {
  int cnt = 0;
  string n;

  while (1) {
    if (cnt++)
      cout << endl;
    cin >> n;

    while (n.size() < 5)
      n = "0" + n;

    vector<string> s(n.size());
    rep(i, n.size()) s[i] = str[n[i] - '0'];

    rep(i, 8) {
      rep(j, n.size()) { cout << s[j][i]; }
      cout << endl;
    }
  }
  return 0;
}
Problem p00128 (C++) — buggy submission, verdict: Runtime Error

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>

using namespace std;

typedef long long ll;
typedef pair<string, int> P;

int main() {

  int d;
  string ge5[] = {"* =", " *="};
  string lt5[] = {" ****", "* ***", "** **", "*** *", "**** "};
  bool isnl = false;
  while (~scanf("%d", &d)) {
    if (isnl)
      cout << endl;
    vector<string> res;

    string str;
    while (d > 0) {
      str += (d % 10) + '0';
      d /= 10;
    }
    reverse(str.begin(), str.end());

    // for(int i=0;i<str.size();i++){if(!isdigit(str[i])) str = str.substr(0,i);
    // break;}
    while (str.size() < 5)
      str = "0" + str;
    for (int i = 0; i < str.size(); i++) {
      string tmp = "";
      tmp = ge5[(str[i] - '0') >= 5 ? 1 : 0];
      tmp = tmp + lt5[(str[i] - '0') % 5];
      res.push_back(tmp);
    }

    while (res.size() < 5)
      res.push_back(ge5[0] + lt5[0]);

    char table[8][5];
    for (int i = 0; i < 8; i++) {
      for (int j = 0; j < 5; j++) {
        table[i][j] = res[j][i];
        // printf("%c%s",res[j][i],j==res.size()-1 ? "\\n" : "");
      }
    }

    for (int i = 0; i < 8; i++) {
      for (int j = 0; j < 5; j++) {
        cout << table[i][j];
      }
      cout << endl;
    }
    isnl = true;
  }

  exit(0);
}

Error: WA

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>

using namespace std;

typedef long long ll;
typedef pair<string, int> P;

int main() {
  string str;
  string ge5[] = {"* =", " *="};
  string lt5[] = {" ****", "* ***", "** **", "*** *", "**** "};
  bool isnl = false;
  while (getline(cin, str)) {
    if (str.empty())
      continue;
    if (isnl)
      cout << endl;
    vector<string> res;

    while (str.size() < 5)
      str = "0" + str;
    for (int i = 0; i < str.size(); i++) {
      string tmp = "";
      tmp = ge5[(str[i] - '0') >= 5 ? 1 : 0];
      tmp = tmp + lt5[(str[i] - '0') % 5];
      res.push_back(tmp);
    }

    while (res.size() < 5)
      res.push_back(ge5[0] + lt5[0]);

    char table[8][5];
    for (int i = 0; i < res[0].size(); i++) {
      for (int j = 0; j < res.size(); j++) {
        table[i][j] = res[j][i];
        // printf("%c%s",res[j][i],j==res.size()-1 ? "\\n" : "");
      }
    }

    for (int i = 0; i < res[0].size(); i++) {
      for (int j = 0; j < res.size(); j++) {
        cout << table[i][j];
      }
      cout << endl;
    }
    isnl = true;
  }

  exit(0);
}
Problem p00129 (C++) — buggy submission, verdict: Time Limit Exceeded

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

struct Wall {
  int x, y, r;
};

bool inside(Wall w, double x, double y) {
  return w.r * w.r >= (w.x - x) * (w.x - x) + (w.y - y) * (w.y - y);
}

int main() {
  int n, wx, wy, r, m, tx, ty, sx, sy;
  while (cin >> n, n) {
    vector<Wall> w;
    for (int i = 0; i < n; ++i) {
      cin >> wx >> wy >> r;
      w.push_back((Wall){wx, wy, r});
    }
    cin >> m;
    for (int i = 0; i < m; ++i) {
      cin >> tx >> ty >> sx >> sy;
      bool safe = false;
      for (int j = 0; j < n && !safe; ++j) {
        int k = inside(w[j], tx, ty) + inside(w[j], sx, sy);
        if (k == 0) {
          double dx, dy, x, y, minx, maxx, miny, maxy;
          dx = (sx - tx) / 10000.0;
          dy = (sy - ty) / 10000.0;
          x = tx;
          y = ty;
          minx = min(sx, tx);
          maxx = max(sx, tx);
          miny = min(sy, ty);
          maxy = max(sy, ty);
          while (!safe && minx <= x && x <= maxx && miny <= y && y <= maxy) {
            if (inside(w[j], x, y)) {
              safe = true;
              break;
            }
            x += dx;
            y += dy;
          }
        } else if (k == 1) {
          safe = true;
        }
      }
      cout << (safe ? "Safe" : "Danger") << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

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

struct Wall {
  int x, y, r;
};

bool inside(Wall w, double x, double y) {
  return w.r * w.r >= (w.x - x) * (w.x - x) + (w.y - y) * (w.y - y);
}

int main() {
  int n, wx, wy, r, m, tx, ty, sx, sy;
  while (cin >> n, n) {
    vector<Wall> w;
    for (int i = 0; i < n; ++i) {
      cin >> wx >> wy >> r;
      w.push_back((Wall){wx, wy, r});
    }
    cin >> m;
    for (int i = 0; i < m; ++i) {
      cin >> tx >> ty >> sx >> sy;
      bool safe = false;
      for (int j = 0; j < n && !safe; ++j) {
        int k = inside(w[j], tx, ty) + inside(w[j], sx, sy);
        if (k == 0) {
          double dx, dy, x, y, minx, maxx, miny, maxy;
          dx = (sx - tx) / 100000.0;
          dy = (sy - ty) / 100000.0;
          x = tx;
          y = ty;
          minx = min(sx, tx);
          maxx = max(sx, tx);
          miny = min(sy, ty);
          maxy = max(sy, ty);
          while (!safe && minx <= x && x <= maxx && miny <= y && y <= maxy) {
            if (inside(w[j], x, y)) {
              safe = true;
              break;
            }
            x += dx;
            y += dy;
          }
        } else if (k == 1) {
          safe = true;
        }
      }
      cout << (safe ? "Safe" : "Danger") << endl;
    }
  }
  return 0;
}
Problem p00130 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    string in_str;
    string ans;
    bool is_checked[256] = {};
    cin >> in_str;

    ans += in_str[0];
    is_checked[in_str[0]] = true;
    // cout << "debug: ascii " << in_str[0] - 'a' << " "
    //      << "in_str[j] = "  << in_str[0] << endl;
    for (int j = 1; j < in_str.size(); j = j + 3) {
      // cout << "debug: ascii " << in_str[j + 2] - 'a' << " "
      //      << "in_str[j + 2] = "  << in_str[j + 2] << endl;
      if (is_checked[in_str[j + 2]]) {
        continue;
      }

      is_checked[in_str[j + 2]] = true;

      if (in_str[j] == '-' && in_str[j + 1] == '>') {
        ans = ans + in_str[j + 2];
      } else if (in_str[j] == '<' && in_str[j + 1] == '-') {
        ans = in_str[j + 2] + ans;
      } else {
        /* Nop */
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Error: -11

Fixed submission:

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

int main() {
  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    string in_str;
    string ans;
    bool is_checked[200] = {};
    cin >> in_str;

    ans += in_str[0];
    is_checked[in_str[0] - 'a'] = true;
    // cout << "debug: ascii " << in_str[0] - 'a' << " "
    //      << "in_str[j] = "  << in_str[0] << endl;
    for (int j = 1; j < in_str.size() - 2; j = j + 3) {
      // cout << "debug: ascii " << in_str[j + 2] - 'a' << " "
      //      << "in_str[j + 2] = "  << in_str[j + 2] << endl;
      if (is_checked[in_str[j + 2] - 'a']) {
        continue;
      }

      is_checked[in_str[j + 2] - 'a'] = true;

      if (in_str[j] == '-' && in_str[j + 1] == '>') {
        ans = ans + in_str[j + 2];
      } else if (in_str[j] == '<' && in_str[j + 1] == '-') {
        ans = in_str[j + 2] + ans;
      } else {
        /* Nop */
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00130 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>

int main() {
  int n;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    char train[60];
    for (int j = 0; j < 60; j++)
      train[j] = '?';
    int it = 30;

    std::string str;
    std::cin >> str;

    train[it] = str[0];
    for (int j = 1; j < str.size(); j++) {
      if (str[j] == '>') {
        it++;
        if (train[it] != str[j + 1])
          train[it] = str[j + 1];
      } else if (str[j] == '<') {
        it--;
        if (train[it] != str[j + 2])
          train[it] = str[j + 2];
      }
    }

    for (int j = 0; j < 60; j++) {
      if (train[j] != '?')
        std::cout << train[j];
    }
    std::cout << std::endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <string>

int main() {
  int n;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    char train[30];
    for (int j = 0; j < 30; j++)
      train[j] = '?';
    int it = 14;

    std::string str;
    std::cin >> str;

    train[it] = str[0];
    for (int j = 1; j < str.size(); j++) {
      if (str[j] == '>') {
        it++;
        if (train[it] != str[j + 1])
          train[it] = str[j + 1];
      } else if (str[j] == '<') {
        it--;
        if (train[it] != str[j + 2])
          train[it] = str[j + 2];
      }
    }

    for (int j = 0; j < 30; j++) {
      if (train[j] != '?')
        std::cout << train[j];
    }
    std::cout << std::endl;
  }
  return 0;
}
Problem p00130 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>
using namespace std;
int main() {

  int n;
  scanf("%d", &n);

  for (int q = 0; q < n; q++) {

    char str[1000] = {0};
    scanf("%s", str);

    char ans[1000] = {0};

    ans[0] = str[0];

    bool check[1280] = {0};

    check[str[0]] = 1;

    int x = 1;
    for (int i = 3; i < strlen(str); i += 3) {

      if (check[str[i]] == 1)
        continue;
      check[str[i]] = 1;

      if (str[i - 1] == '>') {
        ans[x] = str[i];
        x++;
      } else if (str[i - 2] == '<') {
        for (int j = x; j > 0; j--)
          ans[j] = ans[j - 1];
        ans[0] = str[i];
        x++;
      }
    }

    printf("%s\\n", ans);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
using namespace std;
int main() {

  int n;
  scanf("%d", &n);

  for (int q = 0; q < n; q++) {

    char str[100] = {0};
    scanf("%s", str);

    char ans[30] = {0};

    ans[0] = str[0];

    bool check[128] = {0};

    check[str[0]] = 1;

    int x = 1;
    for (int i = 3; i < strlen(str); i += 3) {

      if (check[str[i]] == 1)
        continue;
      check[str[i]] = 1;

      if (str[i - 1] == '>') {
        ans[x] = str[i];
        x++;
      } else if (str[i - 2] == '<') {
        for (int j = x; j > 0; j--)
          ans[j] = ans[j - 1];
        ans[0] = str[i];
        x++;
      }
    }

    printf("%s\\n", ans);
  }

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

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

typedef long long ll;
const double Eps = 1e-5;

using namespace std;

int main() {
  char buf[1024 + 256];
  cin.getline(buf, sizeof(buf));
  int n;
  sscanf(buf, "%d", &n);
  while (n--) {
    cin.getline(buf, sizeof(buf));
    strcat(buf, "--");
    pair<int, char> pos[26];
    for (int i = 0; i < 26; ++i) {
      pos[i].first = 9999;
      pos[i].second = i + 'a';
    }
    int relaPos = 0;
    for (int i = 0; buf[i] != '\\0'; i += 3) {
      pos[buf[i] - 'a'].first = relaPos;
      if (buf[i + 2] == '>')
        ++relaPos;
      else
        --relaPos;
    }
    sort(pos, pos + 26);
    for (int i = 0; pos[i].first != 9999 && i < 26; ++i)
      putchar(pos[i].second);
    putchar('\\n');
  }

  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

typedef long long ll;
const double Eps = 1e-5;

using namespace std;

int main() {
  char buf[1024 + 256];
  cin.getline(buf, sizeof(buf));
  int n;
  sscanf(buf, "%d", &n);
  while (n--) {
    cin.getline(buf, sizeof(buf));
    strcat(buf, "--");
    pair<int, char> pos[26];
    for (int i = 0; i < 26; ++i) {
      pos[i].first = 9999;
      pos[i].second = i + 'a';
    }
    int relaPos = 0;
    for (int i = 0; buf[i] != '\\0'; i += 3) {
      pos[buf[i] - 'a'].first = relaPos;
      if (buf[i + 2] == '>')
        ++relaPos;
      else if (buf[i + 1] == '<')
        --relaPos;
    }
    sort(pos, pos + 26);
    for (int i = 0; pos[i].first != 9999; ++i)
      putchar(pos[i].second);
    putchar('\\n');
  }

  return 0;
}