Problem p01695 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16>>(x);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < (int)(n); i++)
#define if_range(x, y, w, h)                                                   \
  if (0 <= (int)(x) && (int)(x) < (int)(w) && 0 <= (int)(y) &&                 \
      (int)(y) < (int)(h))

const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
using namespace std;
typedef long long ll;
// typedef pair<int, int> P;
/* struct P {
        int x, y, n;
        P(int n, int x, int y):n(n), x(x), y(y){}
        P(){}
}; */

/** Problem2583 : JAG-cannel **/
int main() {
  int N;
  while (cin >> N, N) {
    vector<string> s(N);
    rep(i, N) cin >> s[i];
    REP(i, 1, N) {
      int j = 0;
      for (; j < s[i].size(); j++) {
        if (s[i][j + 1] != '.') {
          s[i][j] = '+';
          break;
        }
      }
      for (int k = i; k > 0; k--) {
        if (s[k - 1][j] == '.') {
          s[k - 1][j] = '|';
        }
      }
    }

    rep(i, N) {
      rep(j, s[i].size()) {
        if (s[i][j] == '.')
          s[i][j] = ' ';
      }
    }

    rep(i, N) { cout << s[i] << endl; }
  }
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16>>(x);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < (int)(n); i++)
#define if_range(x, y, w, h)                                                   \
  if (0 <= (int)(x) && (int)(x) < (int)(w) && 0 <= (int)(y) &&                 \
      (int)(y) < (int)(h))

const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
using namespace std;
typedef long long ll;
// typedef pair<int, int> P;
/* struct P {
        int x, y, n;
        P(int n, int x, int y):n(n), x(x), y(y){}
        P(){}
}; */

/** Problem2583 : JAG-cannel **/
int main() {
  int N;
  while (cin >> N, N) {
    vector<string> s(N);
    rep(i, N) cin >> s[i];
    REP(i, 1, N) {
      int j = 0;
      for (; j < s[i].size(); j++) {
        if (s[i][j + 1] != '.') {
          s[i][j] = '+';
          break;
        }
      }
      for (int k = i - 1; k > 0; k--) {
        if (s[k][j] == '.') {
          s[k][j] = '|';
        } else {
          break;
        }
      }
    }

    rep(i, N) {
      rep(j, s[i].size()) {
        if (s[i][j] == '.')
          s[i][j] = ' ';
      }
    }

    rep(i, N) { cout << s[i] << endl; }
  }
}