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

#include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
template <typename T> void cmax(T &a, T b) { a = max(a, b); }
template <typename T> void cmin(T &a, T b) { a = min(a, b); }
char mp[10001][10000];

signed main() {
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    memset(mp, ' ', sizeof(mp));
    vector<int> end(n);
    int predot = 0;
    rep(i, n) {
      string s;
      cin >> s;
      int dot = 0;
      for (int j = 0; j < s.size(); j++) {
        while (s[j] == '.') {
          j++;
          dot++;
        }
        mp[i][j] = s[j];
      }
      end[i] = s.size();
      mp[i][dot - 1] = '+';
      if (dot < predot) {
        int tmp = 1;
        while (mp[i - tmp][dot - 1] == ' ' && tmp >= 0) {
          mp[i - tmp][dot - 1] = '|';
          tmp++;
        }
      }
      predot = dot;
    }
    rep(i, n) {
      rep(j, end[i]) { cout << mp[i][j]; }
      cout << endl;
    }
  }

  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
template <typename T> void cmax(T &a, T b) { a = max(a, b); }
template <typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    char mp[1003][102];
    memset(mp, ' ', sizeof(mp));
    vector<int> end(n);
    int predot = 0;
    rep(i, n) {
      string s;
      cin >> s;
      int dot = 0;
      for (int j = 0, t = 0; j < s.size(); j++, t++) {
        while (s[j] == '.') {
          j++;
          dot++;
        }
        mp[i][dot + t] = s[j];
        end[i] = dot + t;
      }
      mp[i][dot - 1] = '+';
      if (dot < predot) {
        int tmp = 1;
        while (mp[i - tmp][dot - 1] == ' ') {
          mp[i - tmp][dot - 1] = '|';
          tmp++;
        }
      }
      predot = dot;
    }
    rep(i, n) {
      int j = 0;
      rep(j, end[i]) { cout << mp[i][j]; }
      cout << endl;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
int cnt[1010], n;
string s[1010], z;
int main() {
  while (cin >> n && n) {
    cin >> z;
    cout << z << endl;
    n--;
    memset(cnt, 114514, sizeof(cnt));
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      int k = 0;
      for (int j = s[i].size() - 1; j >= 0; j--) {
        if (s[i][j] == '.')
          s[i][j] = ' ';
        else
          k = j - 1;
      }
      for (int j = k + 1; j < 1010; j++)
        cnt[j] = 114514;
      for (int j = cnt[k]; j < i; j++)
        s[j][k] = '|';
      s[i][k] = '+';
      cnt[k] = i + 1;
    }
    for (int i = 0; i < n; i++)
      cout << s[i] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int cnt[60], n;
string s[1010], z;
int main() {
  while (cin >> n && n) {
    cin >> z;
    cout << z << endl;
    n--;
    memset(cnt, -1, sizeof(cnt));
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      int k = 0;
      for (int j = s[i].size() - 1; j >= 0; j--) {
        if (s[i][j] == '.')
          s[i][j] = ' ';
        else
          k = j - 1;
      }
      for (int j = k + 1; j < 55; j++)
        cnt[j] = -1;
      if (cnt[k] != -1) {
        for (int j = cnt[k] + 1; j < i; j++)
          s[j][k] = '|';
      }
      s[i][k] = '+';
      cnt[k] = i;
    }
    for (int i = 0; i < n; i++)
      cout << s[i] << endl;
  }
  return 0;
}
Problem p01695 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);
int fr[1005];

int main() {
  int n;
  string str;
  while (cin >> n) {
    string res[1005];
    memset(fr, -1, sizeof(fr));
    REP(i, n) {
      cin >> str;
      res[i] = str;
      int depth = 0;
      while (str[depth] == '.') {
        res[i][depth] = ' ';
        depth++;
      }
      if (depth > 0)
        res[i][depth - 1] = '+';
      int tmp = depth;
      if (fr[depth] != -1) {
        for (int j = fr[depth] + 1; j < i; j++)
          res[j][depth - 1] = '|';
        tmp++;
        while (fr[tmp] != -1) {
          fr[tmp] = -1;
          tmp++;
        }
      }
      fr[depth] = i;
    }
    REP(i, n) { cout << res[i] << endl; }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);
string res[1005];
int fr[1005];

int main() {
  int n;
  string str;
  while (cin >> n) {
    memset(res, 0, sizeof(res));
    memset(fr, -1, sizeof(fr));
    REP(i, n) {
      cin >> str;
      res[i] = str;
      int depth = 0;
      while (str[depth] == '.') {
        res[i][depth] = ' ';
        depth++;
      }
      if (depth > 0)
        res[i][depth - 1] = '+';
      int tmp = depth;
      if (fr[depth] != -1) {
        for (int j = fr[depth] + 1; j < i; j++)
          res[j][depth - 1] = '|';
        tmp++;
        while (fr[tmp] != -1) {
          fr[tmp] = -1;
          tmp++;
        }
      }
      fr[depth] = i;
    }
    REP(i, n) { cout << res[i] << endl; }
  }
  return 0;
}
Problem p01695 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrep2(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pll> vp;
typedef vector<ll> vll;

const int MAX_LEN = 1200;
int n;
char s[1000][MAX_LEN];

signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  while (cin >> n && n) {
    rep(i, n) rep(j, MAX_LEN) s[i][j] = '#';
    rep(i, n) {
      string t;
      cin >> t;
      rep(j, t.size()) s[i][j] = t[j];
    }

    // process row by row
    rep(j, MAX_LEN) {
      // make plus and space
      rep(i, n) {
        if (s[i][j] == '.' && s[i][j + 1] != '.') {
          s[i][j] = '+';
        }
        if (s[i][j] == '.' && s[i][j + 1] == '.') {
          s[i][j] = ' ';
        }
      }
      // make line
      rep(i, n) {
        if (s[i][j] == '+') {
          int k = i + 1;
          while (k < n && s[k][j] == ' ')
            k++;
          if (k < n && s[k][j] == '+') {
            rep2(l, i + 1, k) { s[l][j] = '|'; }
          }
        }
      }
    }

    rep(i, n) {
      rep(j, MAX_LEN) {
        if (s[i][j] == '#')
          break;
        cout << s[i][j];
      }
      cout << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrep2(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pll> vp;
typedef vector<ll> vll;

int n;
char s[1000][1000];

signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  while (cin >> n && n) {
    rep(i, n) rep(j, 1000) s[i][j] = '#';
    rep(i, n) {
      string t;
      cin >> t;
      rep(j, t.size()) s[i][j] = t[j];
    }

    // process row by row
    rep(j, 1000) {
      // make plus and space
      rep(i, n) {
        if (s[i][j] == '.' && s[i][j + 1] != '.') {
          s[i][j] = '+';
        }
        if (s[i][j] == '.' && s[i][j + 1] == '.') {
          s[i][j] = ' ';
        }
      }
      // make line
      rep(i, n) {
        if (s[i][j] == '+') {
          int k = i + 1;
          while (k < n && s[k][j] == ' ')
            k++;
          if (k < n && s[k][j] == '+') {
            rep2(l, i + 1, k) { s[l][j] = '|'; }
          }
        }
      }
    }

    rep(i, n) {
      rep(j, 1000) {
        if (s[i][j] == '#')
          break;
        cout << s[i][j];
      }
      cout << endl;
    }
  }
}
Problem p01695 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int n;
vector<string> str;
vector<int> cntDot;
vector<int> checked;

void dfs(int dotn) {
  str[dotn][cntDot[dotn] - 1] = '+';
  checked[dotn] = 1;
  //???????????????????????¢?´¢
  for (int i = dotn + 1; i < n; i++) {
    if (cntDot[dotn] < cntDot[i] && checked[i] != 1)
      dfs(i); //?????????????????????dfs????????????
    if (cntDot[dotn] > cntDot[i])
      break; //????????????????????????????????£??????break
    //????????????????????????'|'??§??????
    if (cntDot[dotn] == cntDot[i]) {
      //'.'???'|'????????????
      if (cntDot[dotn] - 1 >= 0) {
        for (int j = dotn + 1; j < i; j++) {
          str[j][cntDot[dotn] - 1] = '|';
        }
      }
      break;
    }
  }
}

int main() {
  while (cin >> n && n) {
    str = vector<string>(n);
    cntDot = vector<int>(n);
    checked = vector<int>(n);
    for (int i = 0; i < n; ++i) {
      cin >> str[i];
      //??????????????°?????°??????
      for (int j = 0; j < str[i].length(); ++j) {
        if (str[i][j] == '.') {
          ++cntDot[i];
          str[i][j] = ' ';
        } else {
          break;
        }
      }
    }
    for (int i = 1; i < n; i++) {
      dfs(i);
    }
    for (int i = 0; i < n; i++) {
      cout << str[i] << endl;
    }
    str.clear();
    cntDot.clear();
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int n;
vector<string> str;
vector<int> cntDot;

void dfs(int dotn) {
  str[dotn][cntDot[dotn] - 1] = '+';
  //???????????????????????¢?´¢
  for (int i = dotn + 1; i < n; i++) {
    if (cntDot[dotn] < cntDot[i])
      dfs(i); //?????????????????????dfs????????????
    if (cntDot[dotn] > cntDot[i])
      break; //????????????????????????????????£??????break
    //????????????????????????'|'??§??????
    if (cntDot[dotn] == cntDot[i]) {
      //'.'???'|'????????????
      if (cntDot[dotn] - 1 >= 0) {
        for (int j = dotn + 1; j < i; j++) {
          str[j][cntDot[dotn] - 1] = '|';
        }
      }
      break;
    }
  }
}

int main() {
  while (cin >> n && n) {
    str = vector<string>(n);
    cntDot = vector<int>(n);
    for (int i = 0; i < n; ++i) {
      cin >> str[i];
      //??????????????°?????°??????
      for (int j = 0; j < str[i].length(); ++j) {
        if (str[i][j] == '.') {
          ++cntDot[i];
        } else {
          break;
        }
      }
    }
    for (int i = 1; i < n; i++) {
      dfs(i);
    }
    for (int i = 0; i < n; i++) {
      if (i != 0) {
        for (int j = 0; j < str[i].length(); j++) {
          if (str[i][j] == '+')
            break;
          if (str[i][j] == '.')
            str[i][j] = ' ';
        }
      }
      cout << str[i] << endl;
    }
    str.clear();
    cntDot.clear();
  }
  return 0;
}
Problem p01695 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

int main() {
  int n;
  while (cin >> n) {
    if (n == 0) {
      break;
    }
    vector<string> str(n);
    for (int i = 0; i < n; i++) {
      cin >> str[i];
      if (i == 0) {
        continue;
      }
      for (int j = 0; j < str[i].size(); j++) {
        if (str[i][j] != '.') {
          str[i][j - 1] = '+';
          break;
        } else {
          str[i][j] = ' ';
        }
      }
    }
    int a = -1;
    for (int i = 1; i < n; i++) {
      for (int j = 0; j < str[i].size(); j++) {
        if (str[i][j] == '+') {
          if (j < a) {
            for (int k = i - 1; k >= 0; k--) {
              if (str[k][j] == '+') {
                for (int p = k + 1; p < i; p++) {
                  str[p][j] = '|';
                }
                break;
              }
            }
          }
          a = j;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      cout << str[i] << endl;
    }
  }
  return 0;
}

Error: WA

Fixed submission:

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

using namespace std;

int main() {
  int n;
  while (cin >> n) {
    if (n == 0) {
      break;
    }
    vector<string> str(n);
    for (int i = 0; i < n; i++) {
      cin >> str[i];
      if (i == 0) {
        continue;
      }
      for (int j = 0; j < str[i].size(); j++) {
        if (str[i][j] != '.') {
          str[i][j - 1] = '+';
          break;
        } else {
          str[i][j] = ' ';
        }
      }
    }
    int a = -1;
    for (int i = 1; i < n; i++) {
      for (int j = 0; j < str[i].size(); j++) {
        if (str[i][j] == '+') {
          if (j < a) {
            for (int k = i - 1; k >= 0; k--) {
              if (str[k][j] == '+') {
                for (int p = k + 1; p < i; p++) {
                  str[p][j] = '|';
                }
              }
            }
          }
          a = j;
          break;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      cout << str[i] << endl;
    }
  }
  return 0;
}
Problem p01695 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    vector<string> s(n);
    for (auto &e : s) {
      cin >> e;
    }
    for (int i = n - 1; i >= 0; i--) {
      for (int j = 0; s[i][j] == '.'; j++) {
        if (j + 1 < s[i].size() && s[i][j + 1] != '.') {
          s[i][j] = '+';
        } else if (i + 1 < n && j < s[i + 1].size() &&
                   (s[i + 1][j] == '+' || s[i + 1][j] == '|')) {
          s[i][j] = '|';
        } else {
          s[i][j] = ' ';
        }
      }
    }
    for (auto e : s) {
      cout << e << endl;
    }
  }
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    vector<string> s(n);
    for (auto &e : s) {
      cin >> e;
    }
    for (int i = n - 1; i >= 0; i--) {
      for (int j = 0; s[i][j] == '.'; j++) {
        if (j + 1 < s[i].size() && s[i][j + 1] != '.') {
          s[i][j] = '+';
        } else if (i + 1 < n && s[i + 1][j] == '+' || s[i + 1][j] == '|') {
          s[i][j] = '|';
        } else {
          s[i][j] = ' ';
        }
      }
    }
    for (auto e : s) {
      cout << e << endl;
    }
  }
}
Problem p01695 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <string.h>

#define MAX_N 1000

using namespace std;

int N;
char form[MAX_N + 1][10000];
char res[MAX_N + 1][10000];

int dfs(int level, int pnum) {
  int prenum = pnum;
  if (level > 0) {
    res[prenum][level - 1] = '+';
    // res[pnum][level+1] = '\\0';
  }
  strcpy(&res[prenum][level], &form[prenum][level]);

  int i, nexti;
  for (i = prenum + 1; i < N;) {
    if (level < strlen(form[i]) && form[i][level] == '.' &&
        form[i][level + 1] != '.') {
      nexti = dfs(level + 1, i);
      // cout << nexti << endl;
      for (int j = prenum + 1; j < i; j++) {
        res[j][level] = '|';
      }
      prenum = i;
      i = nexti;
    } else {
      break;
    }
  }
  return i;
}

int main() {
  while (1) {
    cin >> N;
    if (N == 0)
      break;
    for (int i = 0; i < N; i++) {
      cin >> form[i];
      for (int j = 0; j < strlen(form[i]); j++) {
        res[i][j] = ' ';
      }
      // res[i][strlen(form[i])] = '\\0';
      // res[i][strlen(form[i])+1] = '\\0';
    }
    dfs(0, 0);
    for (int i = 0; i < N; i++) {
      cout << res[i] << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <string.h>

#define MAX_N 1000

using namespace std;

int N;
char form[MAX_N + 1][10000];
char res[MAX_N + 1][10000];

void dfs(int level, int pnum) {
  int prenum = pnum;
  if (level > 0) {
    res[pnum][level - 1] = '+';
    // res[pnum][level+1] = '\\0';
  }
  strcpy(&res[pnum][level], &form[pnum][level]);
  if (pnum < N - 1 && form[pnum + 1][level] == '.' &&
      form[pnum + 1][level + 1] != '.') {
    for (int i = pnum + 1; i < N; i++) {
      if (form[i][level] == '.' && form[i][level + 1] != '.') {
        dfs(level + 1, i);
        for (int j = prenum + 1; j < i; j++) {
          res[j][level] = '|';
        }
        prenum = i;
      }
    }
  }
}

int main() {
  while (1) {
    cin >> N;
    if (N == 0)
      break;
    for (int i = 0; i < N; i++) {
      cin >> form[i];
      for (int j = 0; j < strlen(form[i]); j++) {
        res[i][j] = ' ';
      }
    }
    dfs(0, 0);
    for (int i = 0; i < N; i++) {
      cout << res[i] << endl;
    }
  }
  return 0;
}
Problem p01695 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

int main() {

  while (1) {
    int n;
    cin >> n;
    if (!n)
      break;
    string s[n];
    for (int i = 0; i < n; i++)
      cin >> s[i];

    for (int i = 1; i < n; i++) {
      for (int j = 0; j < s[i].size(); j++) {
        if (s[i][j] != '.') {
          s[i][j - 1] = '+';
          break;
        } else {
          s[i][j] = ' ';
        }
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < s[i].size(); j++) {
        if (s[i][j] == '+') {
          for (int k = i - 1; k >= 0; k--) {
            if (s[k][j] == ' ')
              s[k][j] = '|';
            else
              break;
          }
        }
      }
    }

    for (int i = 0; i < n; i++) {
      cout << s[i] << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {

  while (1) {
    int n;
    cin >> n;
    if (!n)
      break;
    string s[n];
    for (int i = 0; i < n; i++)
      cin >> s[i];

    for (int i = 1; i < n; i++) {
      for (int j = 0; j < s[i].size(); j++) {
        if (s[i][j] != '.') {
          s[i][j - 1] = '+';
          break;
        } else {
          s[i][j] = ' ';
        }
      }
    }
    for (int i = n - 1; i >= 0; i--) {
      for (int j = 0; j < s[i].size(); j++) {
        if (s[i][j] == '+') {
          for (int k = i - 1; k >= 0; k--) {
            if (s[k][j] == ' ')
              s[k][j] = '|';
          }
        }
      }
    }

    for (int i = 0; i < n; i++) {
      cout << s[i] << endl;
    }
  }
  return 0;
}
Problem p01695 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef queue<P> Q;

#define _CRT_SECURE_NO_WARNINGS

int N = 0;
char s[1000][1051];
int main() {
  while (scanf("%d", &N), N != 0) {
    int start[1051] = {};
    for (int i = 0; i < N; i++) {
      scanf("%s", s[i]);
      if (s[i][0] == '.') {
        for (int j = 0; j < 1050; j++) {
          if (s[i][j + 1] != '.') {
            s[i][j] = '+';
            if (start[j] != 0) {
              for (int k = start[j] + 1; k < i; k++) {
                s[k][j] = '|';
              }
            }
            start[j] = i;
            for (int k = j + 1; k < 1000; k++) {
              start[k] = 0;
            }
            break;
          } else {
            s[i][j] = ' ';
          }
        }
      }
    }
    for (int i = 0; i < N; i++) {
      printf("%s\\n", s[i]);
    }
  }
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef queue<P> Q;

#define _CRT_SECURE_NO_WARNINGS

int N = 0;
int main() {
  while (scanf("%d", &N), N != 0) {
    char s[51];
    for (int i = 0; i < N; i++) {
      scanf("%s", s);
      if (s[0] == '.') {
        for (int j = 0; j < 50; j++) {
          if (s[j + 1] != '.') {
            s[j] = '+';
            break;
          } else {
            s[j] = j == 0 ? '|' : '+';
          }
        }
      }
      printf("%s\\n", s);
    }
  }
  return 0;
}
Problem p01695 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
#define all(c) begin(c), end(c)
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
int dd[] = {0, 1, 0, -1, 0}; // →↓←↑

void solve() {
  int N;
  vi B;
  vi A;
  vs S;
  while (cin >> N, N) {
    B = vi(N + 1100, -1);
    A = vi(N);
    S = vs(N);
    for (int i = 0; i < N; i++) {
      cin >> S[i];
      for (int j = 0; j < S[i].size(); j++) {
        if (S[i][j] != '.') {
          A[i] = j;
          if (j > 0)
            S[i][j - 1] = '+';
          break;
        } else {
          S[i][j] = ' ';
        }
      }
      if (B[A[i]] >= 1) {
        bool flag = true;
        for (int j = B[A[i]] + 1; j < i; j++) {
          if (A[j] < A[i])
            flag = false;
        }
        if (flag) {
          for (int j = B[A[i]] + 1; j < i; j++) {
            S[j][A[i] - 1] = '|';
          }
        }
      }
      B[A[i]] = i;
    }
    for (int i = 0; i < N; i++) {
      cout << S[i] << endl;
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Error: WA

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
#define all(c) begin(c), end(c)
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
int dd[] = {0, 1, 0, -1, 0}; // →↓←↑

void solve() {
  int N;
  vi B;
  vi A;
  vs S;
  while (cin >> N, N) {
    B = vi(N + 1100, -1);
    A = vi(N);
    S = vs(N);
    for (int i = 0; i < N; i++) {
      cin >> S[i];
      for (int j = 0; j < S[i].size(); j++) {
        if (S[i][j] != '.') {
          A[i] = j;
          if (j > 0)
            S[i][j - 1] = '+';
          break;
        } else {
          S[i][j] = ' ';
        }
      }
      if (B[A[i]] >= 1) {
        bool flag = true;
        for (int j = B[A[i]] + 1; j < i; j++) {
          if (A[j] > A[i])
            flag = false;
        }
        if (flag) {
          for (int j = B[A[i]] + 1; j < i; j++) {
            S[j][A[i] - 1] = '|';
          }
        }
      } else {
        B[A[i]] = i;
      }
    }
    for (int i = 0; i < N; i++) {
      cout << S[i] << endl;
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}