Draw Brackets! CodeForces - 770D (模拟)

A sequence of square brackets is regular if by inserting symbols "+" and "1" into it, you can get a regular mathematical expression from it. For example, sequences "[[]][]", "[]" and "[[][[]]]" — are regular, at the same time "][", "[[]" and "[[]]][" — are irregular.

Draw the given sequence using a minimalistic pseudographics in the strip of the lowest possible height — use symbols '+', '-' and '|'. For example, the sequence "[[][]][]" should be represented as:

+-        -++- -+    
|+- -++- -+||   |
||   ||   |||   |
|+- -++- -+||   |
+-        -++- -+

Each bracket should be represented with the hepl of one or more symbols '|' (the vertical part) and symbols '+' and '-' as on the example which is given above.

Brackets should be drawn without spaces one by one, only dividing pairs of consecutive pairwise brackets with a single-space bar (so that the two brackets do not visually merge into one symbol). The image should have the minimum possible height.

The enclosed bracket is always smaller than the surrounding bracket, but each bracket separately strives to maximize the height of the image. So the pair of final brackets in the example above occupies the entire height of the image.

Study carefully the examples below, they adequately explain the condition of the problem. Pay attention that in this problem the answer (the image) is unique.

Input

The first line contains an even integer n (2 ≤ n ≤ 100) — the length of the sequence of brackets.

The second line contains the sequence of brackets — these are n symbols "[" and "]". It is guaranteed that the given sequence of brackets is regular.

Output

Print the drawn bracket sequence in the format which is given in the condition. Don't print extra (unnecessary) spaces.

Examples

Input

8
[[][]][]

Output

+-        -++- -+
|+- -++- -+||   |
||   ||   |||   |
|+- -++- -+||   |
+-        -++- -+

Input

6
[[[]]]

Output

+-     -+
|+-   -+|
||+- -+||
|||   |||
||+- -+||
|+-   -+|
+-     -+

Input

6
[[][]]

Output

+-        -+
|+- -++- -+|
||   ||   ||
|+- -++- -+|
+-        -+

Input

2
[]

Output

+- -+
|   |
+- -+

Input

4
[][]

Output

+- -++- -+
|   ||   |
+- -++- -+

题意很简单不说了

思路:它们都是上下对称的所以先弄上面一半然后对称过去就好了

难点就是如何把上半部分弄出来

通过观察可以看出两个+号相隔有两种情况,一种是[]相邻,一种是[...]有嵌套

相邻的时候两个+相隔3

然后处理完上半部分,然后上下对称过去,然后上下的两个+之间就是|了

具体看代码:

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define INF 0x3f3f3f3f
using namespace std;
const int maxn=1e5+5;
char a[maxn],ans[105][305];
int n;
void solve()
{
    int w=0,h=0,d=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]=='[')
        {
            ans[d][w]='+';
            ans[d][w+1]='-';
            d++,w++;
        }
        else
        {
            d--;
            if(a[i-1]=='[') w+=3;
            ans[d][w]='+';
            ans[d][w-1]='-';
            w++;
        }
        h=max(h,d);
    }
    for(int i=h+1;i<=2*h;i++)
    {
        for(int j=0;j<w;j++)
        {
            ans[i][j]=ans[2*h-i][j];
        }
    }
    for(int j=0;j<w;j++) {
        for(int i=0,f=0;i<=2*h;i++) {
            if(ans[i][j]=='+')f^=1;
            else if(!ans[i][j])
                ans[i][j]=" |"[f];

        }
    }
    for(int i=0;i<=2*h;i++) {
        printf("%s\n",ans[i]);
    }
}
int main()
{
    scanf("%d%s",&n,a);
    solve();
    return 0;
}

 

微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值