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

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

bool isByTurn(char leg1, char leg2) {
  if (leg1 != leg2)
    return true;
  else
    return false;
}

bool isOnFloor(char right_leg, char left_leg) {
  if (right_leg == 'd' && left_leg == 'd')
    return true;
  else
    return false;
}

bool isOnStep(char right_leg, char left_leg) {
  if (right_leg == 'u' && left_leg == 'u')
    return true;
  else
    return false;
}

int main(void) {
  int n;
  while (cin >> n, n) {
    int ans = 0;
    vector<string> action;
    char right_leg = 'd';
    char left_leg = 'd';
    for (int i = 0; i < n; i++) {
      string tmp;
      cin >> tmp;
      action.push_back(tmp);
    }
    if (n == 1) {
      cout << 0 << endl;
      continue;
    }

    for (int i = 0; i < n - 1; i++) {
      if (isOnFloor(right_leg, left_leg) &&
          isByTurn(action[i][0], action[i + 1][0])) {

        i++;
        ans++;
        right_leg = 'u';
        left_leg = 'u';

      } else if (isOnStep(right_leg, left_leg) &&
                 isByTurn(action[i][0], action[i + 1][0])) {
        i++;
        ans++;
        right_leg = 'd';
        left_leg = 'd';

      } else {
        if (action[i][0] == 'l') {
          left_leg = action[i][1];
        } else {
          right_leg = action[i][1];
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

bool isByTurn(char leg1, char leg2) {
  if (leg1 != leg2)
    return true;
  else
    return false;
}

bool isOnFloor(char right_leg, char left_leg) {
  if (right_leg == 'd' && left_leg == 'd')
    return true;
  else
    false;
}

bool isOnStep(char right_leg, char left_leg) {
  if (right_leg == 'u' && left_leg == 'u')
    return true;
  else
    false;
}

int main(void) {
  int n;
  while (cin >> n, n) {
    int ans = 0;
    vector<string> action;
    char right_leg = 'd';
    char left_leg = 'd';
    for (int i = 0; i < n; i++) {
      string tmp;
      cin >> tmp;
      action.push_back(tmp);
    }
    if (n == 1) {
      cout << 0 << endl;
      continue;
    }

    for (int i = 0; i < n; i++) {
      if (isOnFloor(right_leg, left_leg) &&
          isByTurn(action[i][0], action[i + 1][0])) {
        i++;
        ans++;
        right_leg = 'u';
        left_leg = 'u';

      } else if (isOnStep(right_leg, left_leg) &&
                 isByTurn(action[i][0], action[i + 1][0])) {
        i++;
        ans++;
        right_leg = 'd';
        left_leg = 'd';

      } else {
        if (action[i][0] == 'l') {
          left_leg = action[i][1];
        } else {
          right_leg = action[i][1];
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p01694 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;
int n;

void solve() {
  vector<string> f(n);
  for (int i = 0; i < n; i++)
    cin >> f[i];

  int l = 0, r = 0;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (i + 1 >= n)
      break;
    if (f[i] == "lu" and f[i + 1] == "ru")
      ans++;
    else if (f[i] == "ru" and f[i + 1] == "lu")
      ans++;
    else if (f[i] == "ld" and f[i + 1] == "rd")
      ans++;
    else if (f[i] == "rd" and f[i + 1] == "ld")
      ans++;
  }
  cout << ans << endl;
}

int main() {
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    solve();
  }
}


Error: -11

Fixed submission:

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

using namespace std;
int n;

void solve() {
  vector<string> f(n);
  for (int i = 0; i < n; i++)
    cin >> f[i];

  int l = 0, r = 0;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (f[i] == "lu" and f[i + 1] == "ru")
      ans++;
    else if (f[i] == "ru" and f[i + 1] == "lu")
      ans++;
    else if (f[i] == "ld" and f[i + 1] == "rd")
      ans++;
    else if (f[i] == "rd" and f[i + 1] == "ld")
      ans++;
  }
  cout << ans << endl;
}

int main() {
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    solve();
  }
}
Problem p01694 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <bits/stdc++.h>

using namespace std;

char stem[300];

int main() {
  while (1) {
    int n;
    scanf("%d", &n);
    if (n == 0)
      break;

    char step[300];
    int i;
    for (i = 0; i < 2 * n; i += 2)
      cin >> stem[i] >> stem[i + 1];

    int j, flag = 0, flagl = 0, flagr = 0, ans = 0;
    for (j = 0; j < n; j++) {
      if (stem[2 * j] == 'l') {
        if (stem[2 * j + 1] == 'u')
          flagl = 1;
        else if (stem[2 * j + 1] == 'd')
          flagl = 0;
        else
          printf("e1\\n");
      }
      if (stem[2 * j] == 'r') {
        if (stem[2 * j + 1] == 'u')
          flagr = 1;
        else if (stem[2 * j + 1] == 'd')
          flagr = 0;
        else
          printf("e2\\n");
      }
      if (flag == 0) {
        if (flagl == 1 && flagr == 1) {
          ans++;
          flag = 1;
        }
      }
      if (flag == 1) {
        if (flagl == 0 && flagr == 0) {
          ans++;
          flag = 0;
        }
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

char stem[100];

int main() {
  while (1) {
    int n;
    scanf("%d", &n);
    // if(n==0) break;

    char step[300];
    int i;
    for (i = 0; i < 2 * n; i += 2)
      cin >> stem[i] >> stem[i + 1];

    int j, flag = 0, flagl = 0, flagr = 0, ans = 0;
    for (j = 0; j < n; j++) {
      if (stem[2 * j] == 'l') {
        if (stem[2 * j + 1] == 'u')
          flagl = 1;
        else if (stem[2 * j + 1] == 'd')
          flagl = 0;
        else
          printf("e1\\n");
      }
      if (stem[2 * j] == 'r') {
        if (stem[2 * j + 1] == 'u')
          flagr = 1;
        else if (stem[2 * j + 1] == 'd')
          flagr = 0;
        else
          printf("e2\\n");
      }
      if (flag == 0) {
        if (flagl == 1 && flagr == 1) {
          ans++;
          flag = 1;
        }
      }
      if (flag == 1) {
        if (flagl == 0 && flagr == 0) {
          ans++;
          flag = 0;
        }
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p01694 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  while (1) {
    int n;
    int sum = 0;
    int flag = 0;
    int p = 0;
    string ud[100];

    cin >> n;
    if (n == 0)
      return 0;
    for (int i = 0; i < n; i++) {
      cin >> ud[i];
      if (ud[i] == "ru" || ud[i] == "lu") {
        p++;
      }
      if (ud[i] == "rd" || ud[i] == "ld") {
        p--;
      }
      if (p % 2 == 0 && p != flag) {
        flag = p;
        sum++;
      }
    }
    cout << sum << "\\n";
  }
}


Error: 0

Fixed submission:

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

int main() {
  string s;
  int n, sum, i, j;
  int flag;
  int p;
  string ud[100];
  int ans[100];

  cin >> n;
  for (j = 0; n != 0; j++) {
    sum = 0;
    p = 0;
    flag = 0;
    for (i = 0; i < n; i++) {
      cin >> ud[i];
      if (ud[i] == "ru" || ud[i] == "lu") {
        p++;
      }
      if (ud[i] == "rd" || ud[i] == "ld") {
        p--;
      }
      if (p % 2 == 0 && p != flag) {
        flag = p;
        sum++;
      }
    }
    ans[j] = sum;
    cin >> n;
  }

  for (i = 0; i < j; i++) {
    cout << ans[i] << "\\n";
  }

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

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define all(c) c.begin(), c.end()
#define sz(c) ((int)c.size())
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;

signed main() {
  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      break;

    vector<string> s(n);
    rep(i, 0, n) { cin >> s[i]; }
    rep(i, 0, n) {
      if (s[i][0] != '.')
        continue;
      rep(j, 0, sz(s[i]) - 1) {
        if (s[i][j + 1] != '.') {
          int r = i - 1;
          while (r >= 0 && s[r][j] == '.') {
            s[r][j] = '|';
            r--;
          }
          s[i][j] = '+';
          break;
        }
      }
    }
    rep(i, 0, n) {
      rep(j, 0, sz(s[i])) {
        if (s[i][j] == '.')
          s[i][j] = ' ';
      }
      cout << s[i] << endl;
    }
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define all(c) c.begin(), c.end()
#define sz(c) ((int)c.size())
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;

signed main() {
  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      break;

    vector<string> s(n);
    rep(i, 0, n) { cin >> s[i]; }
    rep(i, 0, n) {
      if (s[i][0] != '.')
        continue;
      rep(j, 0, sz(s[i]) - 1) {
        if (s[i][j + 1] != '.') {
          int r = i - 1;
          while (r >= 0 && s[r][j] == '.') {
            s[r][j] = '|';
            r--;
          }
          s[i][j] = '+';
          break;
        }
      }
    }
    rep(i, 0, n) {
      rep(j, 0, sz(s)) {
        if (s[i][j] == '.')
          s[i][j] = ' ';
      }
      cout << s[i] << endl;
    }
  }
}
Problem p01695 (C++) — buggy submission, verdict: Runtime Error

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define debug(x) cerr << #x << ": " << x << endl;

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const int inf = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  while (cin >> n, n) {
    string s[1100];
    rep(i, n) cin >> s[i];
    int a[1100] = {};
    rep(i, n) {
      rep(j, s[i].size()) {
        if (s[i][j] == '.')
          a[i]++;
        else
          break;
      }
    }
    bool b[1100] = {};
    rrep(i, n) {
      rep(j, a[i] - 1) {
        if (b[j])
          s[i][j] = '|';
      }
      REP(j, a[i], 1000) b[j] = false;
      if (a[i] > 0) {
        s[i][a[i] - 1] = '+';
        if (!b[a[i] - 1])
          b[a[i] - 1] = true;
      }
    }
    rep(i, n) rep(j, s[i].size()) if (s[i][j] == '.') s[i][j] = ' ';
    rep(i, n) cout << s[i] << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define debug(x) cerr << #x << ": " << x << endl;

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const int inf = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  while (cin >> n, n) {
    string s[1100];
    rep(i, n) cin >> s[i];
    int a[1100] = {};
    rep(i, n) {
      rep(j, s[i].size()) {
        if (s[i][j] == '.')
          a[i]++;
        else
          break;
      }
    }
    bool b[100] = {};
    rrep(i, n) {
      rep(j, a[i] - 1) {
        if (b[j])
          s[i][j] = '|';
        if (j > a[i]) {
          b[j] = false;
          break;
        }
      }

      if (a[i] > 0) {
        s[i][a[i] - 1] = '+';
        if (!b[a[i] - 1])
          b[a[i] - 1] = true;
      }
    }
    rep(i, n) rep(j, s[i].size()) if (s[i][j] == '.') s[i][j] = ' ';
    rep(i, n) cout << s[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 < int(n); ++i)
#define SZ(a) ((int)(a.size()))
int n;

string in[10000];

void solve() {
  rep(i, n) cin >> in[i];
  rep(i, n) {
    int idx = -1;
    rep(j, SZ(in[i])) {
      if (in[i][j] != '.') {
        if (j) {
          in[i][j - 1] = '+';
          idx = j - 1;
        }
        break;
      }
    }
    if (idx >= 0)
      for (int k = i - 1; k; --k) {
        if (isalpha(in[k][idx]) || in[k][idx] == '+')
          break;
        in[k][idx] = '|';
      }
  }
  rep(i, n) for (auto &c : in[i]) if (c == '.') c = ' ';
  rep(i, n) cout << in[i] << endl;
}

int main(int argc, char *argv[]) {

  while (cin >> n && n)
    solve();
  return 0;
}

Error: 0

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define SZ(a) ((int)(a.size()))
int n;

string in[100];

void solve() {
  rep(i, n) cin >> in[i];
  rep(i, n) {
    int idx = -1;
    rep(j, SZ(in[i])) {
      if (in[i][j] != '.') {
        if (j) {
          in[i][j - 1] = '+';
          idx = j - 1;
        }
        break;
      }
    }
    if (idx >= 0)
      for (int k = i - 1; k; --k) {
        if (isalpha(in[k][idx]) || in[k][idx] == '+')
          break;
        in[k][idx] = '|';
      }
  }
  rep(i, n) for (auto &c : in[i]) if (c == '.') c = ' ';
  rep(i, n) cout << in[i] << endl;
}

int main(int argc, char *argv[]) {

  while (cin >> n && n)
    solve();
  return 0;
}
Problem p01695 (C++) — buggy submission, verdict: Runtime Error


#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

vector<string> s;

int main() {
  while (1) {
    int n;
    cin >> n;
    if (!n)
      break;

    for (int i = 0; i < n; ++i) {
      string ss;
      cin >> ss;
      s.push_back(ss);
    }
    for (int i = 0; i < n; ++i) {
      int j = 0;
      for (; s[i][j] == '.'; ++j) {
      }
      if (j)
        s[i][j - 1] = '+';
    }
    bool frag = true;
    while (frag) {
      frag = false;
      for (int i = 0; i < n - 1; ++i) {
        for (int j = 0; j < s[i].length(); ++j) {
          if (s[i][j] == '.' && s[i + 1].length() > j &&
              (s[i + 1][j] == '+' || s[i + 1][j] == '|')) {
            s[i][j] = '|';
            frag = true;
          }
          if (s[i][j] == '+')
            break;
        }
      }
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < s[i].length(); ++j) {
        if (s[i][j] == '.')
          s[i][j] = ' ';
        if (s[i][j] == '+')
          break;
      }
    }
    for (int i = 0; i < n; ++i) {
      cout << s[i] << endl;
    }
    while (s.size() > 0) {
      s.pop_back();
    }
  }
  return 0;
}

Error: 0

Fixed submission:


#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

vector<string> s;

int main() {
  while (1) {
    int n;
    cin >> n;
    if (!n)
      break;

    for (int i = 0; i < n; ++i) {
      string ss;
      cin >> ss;
      s.push_back(ss);
    }
    for (int i = 0; i < n; ++i) {
      int j = 0;
      for (; s[i][j] == '.'; ++j) {
      }
      if (j)
        s[i][j - 1] = '+';
    }
    bool frag = true;
    while (frag) {
      frag = false;
      for (int i = 0; i < n - 1; ++i) {
        for (int j = 0;; ++j) {
          if (s[i][j] == '.' && (s[i + 1][j] == '+' || s[i + 1][j] == '|')) {
            s[i][j] = '|';
            frag = true;
          }
          if (s[i][j] == '+')
            break;
        }
      }
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0;; ++j) {
        if (s[i][j] == '.')
          s[i][j] = ' ';
        if (s[i][j] == '+')
          break;
      }
    }
    for (int i = 0; i < n; ++i) {
      cout << s[i] << endl;
    }
    s.clear();
  }
  return 0;
}
Problem p01695 (C++) — buggy submission, verdict: Runtime Error

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

int dotCnt(string s) {
  int c = 0;
  while (s[c] == '.')
    c++;
  return c;
}

int main(void) {
  while (1) {
    int n;
    string s;
    cin >> n;
    if (n == 0)
      break;

    vector<string> ls;
    vector<int> dc;

    char pref[1050][2000];

    for (int i = 0; i < n; i++) {
      cin >> s;
      ls.push_back(s);
      dc.push_back(dotCnt(ls[i]));

      for (int j = 0; j < dc[i]; j++) {
        if (j == dc[i] - 1)
          pref[i][j] = '+';
        else
          pref[i][j] = ' ';
      }
    }

    for (int i = n - 1; i > 0; i--) {
      int pos = i;
      for (int j = i - 1; j > 0; j--) {
        if (dc[i] > dc[j])
          break;
        if (dc[i] == dc[j]) {
          pos = j;
          break;
        }
      }
      for (int j = i - 1; j > pos; j--)
        pref[j][dc[i] - 1] = '|';
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < dc[i]; j++) {
        cout << pref[i][j];
      }
      cout << ls[i].substr(dc[i], ls[i].size() - dc[i]) << endl;
    }
  }

  return 0;
}

Error: -11

Fixed submission:

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

int dotCnt(string s) {
  int c = 0;
  while (s[c] == '.')
    c++;
  return c;
}

int main(void) {
  int n;
  while (1) {
    cin >> n;
    if (n == 0)
      break;

    vector<string> ls;
    ls.reserve(n);
    vector<int> dc;
    vector<vector<char>> pref;
    pref.reserve(n);

    for (int i = 0; i < n; i++) {
      cin >> ls[i];
      int d = dotCnt(ls[i]);
      dc.push_back(d);

      for (int j = 0; j < d - 1; j++)
        pref[i].push_back(' ');
      pref[i].push_back('+');
    }

    pref[0].clear();

    for (int i = n - 1; i >= 0; i--) {
      for (int j = i - 1; j >= 0; j--) {
        if (dc[i] >= dc[j])
          break;
        pref[j][dc[i] - 1] = '|';
      }
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < pref[i].size(); j++) {
        cout << pref[i][j];
      }
      cout << ls[i].substr(dc[i], ls[i].size() - dc[i]) << endl;
    }
  }

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

#include <iostream>
using namespace std;
int main(void) {

  while (1) {
    int n;
    scanf("%d", &n);
    if (n == 0)
      break;
    char s[n][1919];
    for (int i = 0; i < n; i++)
      scanf("%s", s[i]);
    int a[n];
    for (int i = 0; i < n; i++)
      for (int j = 0;; j++) {
        if (s[i][j] != '.') {
          a[i] = j;
          break;
        }
      }
    for (int i = 0; i < n; i++) {
      if (a[i] != 0)
        s[i][a[i] - 1] = '+';
    }
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        if (a[i] > a[j])
          break;
        if (a[i] == a[j]) {
          for (int k = i + 1; k < j; k++)
            s[k][a[i] - 1] = '|';
          break;
        }
      }
    }
    for (int i = 0; i < n; i++)
      for (int j = 0; j < a[i]; j++)
        if (s[i][j] == '.')
          s[i][j] = ' ';
    for (int i = 0; i < n; i++)
      printf("%s\\n", s[i]);
  }

  return 0;
}


Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {

  while (1) {
    int n;
    scanf("%d", &n);
    if (n == 0)
      break;
    char s[n][114];
    for (int i = 0; i < n; i++)
      scanf("%s", s[i]);
    int a[n];
    for (int i = 0; i < n; i++)
      for (int j = 0;; j++) {
        if (s[i][j] != '.') {
          a[i] = j;
          break;
        }
      }
    for (int i = 0; i < n; i++) {
      if (a[i] != 0)
        s[i][a[i] - 1] = '+';
    }
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        if (a[i] > a[j])
          break;
        if (a[i] == a[j]) {
          for (int k = i + 1; k < j; k++)
            s[k][a[i]] = '|';
          break;
        }
      }
    }
    for (int i = 0; i < n; i++)
      for (int j = 0; j < a[i]; j++)
        if (s[i][j] == '.')
          s[i][j] = ' ';
    for (int i = 0; i < n; i++)
      printf("%s\\n", s[i]);
  }

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
    vector<string> vec(n);
    vector<int> depth(n, 0);
    rep(i, n) {
      cin >> vec[i];
      rep(j, vec[i].size()) {
        if (vec[i][j] == '.' && vec[i][j + 1] != '.') {
          vec[i][j] = '+';
          depth[i] = j + 1;
          break;
        }
      }
      for (int j = i - 1; j >= 0; j--) {
        if (depth[i] > depth[j])
          break;
        if (depth[i] == depth[j]) {
          for (int k = j + 1; k < i; k++)
            vec[k][depth[j] - 1] = '|';
          break;
        }
      }
    }
    rep(i, n) {
      rep(j, vec[i].size()) {
        if (vec[i][j] == '.')
          vec[i][j] = ' ';
      }
    }
    rep(i, n) cout << vec[i] << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
  int n;
  int count;
  while (cin >> n, n) {
    string s[50];
    rep(i, n) cin >> s[i];
    rep(i, n) {
      if (s[i][0] == '.') {
        int x = 0;
        while (1) {
          if (s[i][x] != '.') {
            s[i][x - 1] = '+';
            break;
          }
          x++;
        }
      }
    }
    rep(i, n) if (s[i][0] == '.') s[i][0] = '|';
    int x = 0;
    // rep(i,n) cout << s[i] << endl;
    rep(i, n) {
      x = 0;
      while (1) {
        if (s[i][x] != '|' && s[i][x] != '+' && s[i][x] != '.')
          break;
        if (s[i][x] == '.' && s[i][x + 1] == '+') {
          if (s[i + 1][x] == s[i][x] && s[i + 1][x + 1] == s[i][x + 1] &&
                  i < n - 1 ||
              s[i - 1][x] == '|') {
            s[i][x] = '|';
          }
        }
        x++;
      }
    }
    for (int i = 1; i < n; i++) {
      x = 0;
      while (1) {
        if (s[i][x] == '+')
          break;
        if (s[i][x] == '.')
          s[i][x] = ' ';
        x++;
      }
    }
    if (s[n - 1][0] == '|' && s[n - 1][1] == '+')
      s[n - 1][0] = ' ';
    rep(i, n) cout << s[i] << endl;
  }
  return 0;
}
Problem p01695 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
using namespace std;

int main() {
  int n;
  char s[1000][1060];
  int counter[1000];
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      return 0;
    for (int i = 0; i < n; i++)
      scanf("%s", s[i]);
    for (int i = 0; i < n; i++)
      for (counter[i] = 0; s[i][counter[i]] == '.'; counter[i]++)
        s[i][counter[i]] = ' ';
    for (int i = 0; i < n; i++)
      counter[i]--;
    printf("%s\\n", s[0]);
    for (int i = 1; i < n; i++) {
      s[i][counter[i]] = '+';
      if (counter[i - 1] > counter[i]) {
        for (int j = i - 1; counter[j] > counter[i]; j--)
          s[j][counter[i]] = '|';
      }
    }
    for (int i = 1; i < n; i++)
      printf("%s\\n", s[i]);
  }
}


Error: WA

Fixed submission:

#include <cstdio>
using namespace std;

int main() {
  int n;
  char s[1000][60];
  int counter[1000];
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (int i = 0; i < n; i++)
      scanf("%s", s[i]);
    for (int i = 0; i < n; i++)
      for (counter[i] = 0; s[i][counter[i]] == '.'; counter[i]++)
        s[i][counter[i]] = ' ';
    int maxC = 0;
    printf("%s\\n", s[0]);
    for (int i = 1; i < n; i++) {
      s[i][counter[i]] = '+';
      if (counter[i - 1] > counter[i]) {
        for (int j = i - 1; counter[j] > counter[i]; j--)
          s[j][counter[i]] = '|';
      }
    }
    for (int i = 1; i < n; i++)
      printf("%s\\n", s[i]);
  }
}