Language: Java

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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)

int read(){
  int i;
  scanf("%lld",&i);
  return i;
}

signed main(){
  while(true){
    int n=read();
    if(n==0) return 0;
    string s[n];
    int cnt[n];
    int cnt_max=0;
    // cin >> s[0];
    // FOR(i,1,n){
    REP(i, n){
      // int first,last;
      int last;
      cin >> s[i];
      // first = s[i].find_first_of('.');
      last = s[i].find_last_of('.');
      if (last == -1) {
        cnt[i] = -1;
        continue;
      }
      s[i][last] = '+';
      // cnt[i] = last-first;
      cnt[i] = last;
      cnt_max = max(cnt_max,cnt[i]);
    }
    FOR(j,0,cnt_max+1){
      // int first=0,last=0;
      FOR(i,1,n){
        if(cnt[i] == j){
          // if(first == 0) first = i;
          // else last = i;
          for (int k = i + 1; k < n; ++k) {
            if (cnt[k] < j) {
              break;
            }
            if (cnt[k] == j) {
              int first = i;
              int last = k;
              FOR (l, first + 1, last) {
                s[l][j] = '|';
              }
            }
          }
        }
      }
      // FOR(k,first+1,last){
      //   if(s[k].length() >= j) continue;
      //   if(s[k][j] == '.') s[k][j] = '|';
      // }
    }

    FOR(i,1,n){
      REP(j,cnt[i]){
        if(s[i][j] == '.') s[i][j] = ' ';
      }
    }
    REP(i,n) cout << s[i] << endl;
  }
}

Compiler output:
Main.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
Main.java:1: error: class, interface, enum, or record expected
#include <bits/stdc++.h>
         ^
Main.java:4: error: unnamed classes are a preview feature and are disabled by default.
using ll=long long;
^
  (use --enable-preview to enable unnamed classes)
Main.java:4: error: '.class' expected
using ll=long long;
              ^
Main.java:5: error: illegal character: '#'
#define int ll
^
Main.java:7: error: illegal character: '#'
#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
^
Main.java:7: error: class, interface, enum, or record expected
#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
                                    ^
Main.java:7: error: class, interface, enum, or record expected
#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
                                             ^
Main.java:8: error: illegal character: '#'
#define REP(i,b) FOR(i,0,b)
^
Main.java:12: error: class, interface, enum, or record expected
  scanf("%lld",&i);
  ^
Main.java:13: error: class, interface, enum, or record expected
  return i;
  ^
Main.java:14: error: class, interface, enum, or record expected
}
^
Main.java:19: error: class, interface, enum, or record expected
    if(n==0) return 0;
    ^
Main.java:20: error: class, interface, enum, or record expected
    string s[n];
    ^
Main.java:21: error: class, interface, enum, or record expected
    int cnt[n];
    ^
Main.java:25: error: class, interface, enum, or record expected
    REP(i, n){
    ^
Main.java:28: error: class, interface, enum, or record expected
      cin >> s[i];
      ^
Main.java:30: error: class, interface, enum, or record expected
      last = s[i].find_last_of('.');
      ^
Main.java:31: error: class, interface, enum, or record expected
      if (last == -1) {
      ^
Main.java:33: error: class, interface, enum, or record expected
        continue;
        ^
Main.java:34: error: class, interface, enum, or record expected
      }
      ^
Main.java:37: error: class, interface, enum, or record expected
      cnt[i] = last;
      ^
Main.java:38: error: class, interface, enum, or record expected
      cnt_max = max(cnt_max,cnt[i]);
      ^
Main.java:39: error: class, interface, enum, or record expected
    }
    ^
Main.java:46: error: class, interface, enum, or record expected
          for (int k = i + 1; k < n; ++k) {
                              ^
Main.java:46: error: class, interface, enum, or record expected
          for (int k = i + 1; k < n; ++k) {
                                     ^
Main.java:49: error: class, interface, enum, or record expected
            }
            ^
Main.java:53: error: class, interface, enum, or record expected
              FOR (l, first + 1, last) {
              ^
Main.java:55: error: class, interface, enum, or record expected
              }
              ^
Main.java:69: error: class, interface, enum, or record expected
      }
      ^
Main.java:72: error: class, interface, enum, or record expected
  }
  ^
31 errors