https://codeforces.com/contest/1101/problem/B

题解:

从左往右找到 [: :下标为l

从右往左找到 :] :下标为r

查找【l+1,r-1】区间上的 数量cnt

答案就是cnt+4

如果不能满足l<r或者找不到 [: 和 :]任意一个那么不存在 

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q;
int ans,cnt,flag,temp;
int a[N];
string  str;
stack<char>st1;
stack<char>st2;
int main()
{
#ifdef DEBUG
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#endif
    //scanf("%d",&n);
    //scanf("%d",&t);
    //while(t--){}
    cin>>str;
    int len=str.size();
    flag=0;
    int l=0,r=len-1;
    for(int i=0;i<len;i++){
        if(str[i]=='['&&st1.size()==0){
            st1.push('[');
        }
        if(str[i]==':'&&st1.size()==1){
            l=i;
            st1.push(':');
            break;
        }
    }
    for(int i=len;i>0;i--){
        if(str[i]==']'&&st2.size()==0){
            st2.push(']');
        }
        if(str[i]==':'&&st2.size()==1){
            r=i;
            st2.push(':');
            break;
        }
    }
    if(st1.size()!=2||st2.size()!=2||l>=r||l==0||r==len-1){
        cout<<-1<<endl;
    }else{
        for(int i=l+1;i<r;i++){
            if(str[i]=='|'){
                cnt++;
            }
        }
        cout<<cnt+4<<endl;
    }

    //cout << "Hello world!" << endl;
    return 0;
}