<span>Accordion CodeForces - 1101B (实现)</span>

An accordion is a string (yes, in the real world accordions are musical instruments, but let's forget about it for a while) which can be represented as a concatenation of: an opening bracket (ASCII code 091091), a colon (ASCII code 058058), some (possibly zero) vertical line characters (ASCII code 124124), another colon, and a closing bracket (ASCII code 093093). The length of the accordion is the number of characters in it.

For example, [::], [:||:] and [:|||:] are accordions having length 44, 66 and 77. (:|:), {:||:}, [:], ]:||:[ are not accordions.

You are given a string ss. You want to transform it into an accordion by removing some (possibly zero) characters from it. Note that you may not insert new characters or reorder existing ones. Is it possible to obtain an accordion by removing characters from ss, and if so, what is the maximum possible length of the result?

Input

The only line contains one string ss (1|s|5000001≤|s|≤500000). It consists of lowercase Latin letters and characters [, ], : and |.

Output

If it is not possible to obtain an accordion by removing some characters from ss, print 1−1. Otherwise print maximum possible length of the resulting accordion.

Examples

Input
|[a:b:|]
Output
4
Input
|]:[|:]
Output
-1
 
 
题目链接:CodeForces - 1101B 
有人说这是一个阅读理解题,觉得有点道理,读懂题后就很简单了,写代码的时候细心一点,情况多多判断就可以了。
题意:给你一个手风琴的字符串模型的定义,然后给你一个字符串,你可以删除这个字符串中的一些或者0个字符,使之成为一个符合定义的字符串,
问这个处理后的字符串最大的长度?
思路:既然题目给定了字符串的定义为[: ||| :] 即左右有开关口的方括号,方括号里面有两个':',':'里面有若干个(可能0个)的'|'字符,
那么只需要处理下左右的方括号后再对里面找对应的字符就好了。
具体细节可以看代码。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
char s[maxn];
int n;
int main()
{
    scanf("%s",s);
    n=strlen(s);
    int spos=-1;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='[')
        {
            spos=i;
            break;
        }
    }
    int epos=-1;
    for(int i=n-1;i>=0;i--)
    {
        if(s[i]==']')
        {
            epos=i;
            break;
        }
    }

    if(epos==-1||spos==-1||(spos>epos))
    {
        printf("-1\n");
    }else
    {
        int cnt=0;
        int ssp=-1;
        int eep=-1;
        for(int i=spos;i<=epos;i++)
        {
            if(s[i]==':')
            {
                eep=max(eep,i);
                if(ssp==-1)
                {
                    ssp=i;
                }
                cnt++;
            }

        }
        if(cnt<2)
        {
            printf("-1\n");
        }else
        {
            int ans=4;
            for(int i=ssp;i<=eep;i++)
            {
                if(s[i]=='|')
                {
                    ans++;
                }
            }
            printf("%d",ans);
        }
    }
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}

 


全部评论

相关推荐

05-12 16:04
已编辑
江西财经大学 Java
点赞 评论 收藏
分享
吐泡泡的咸鱼:我也工作了几年了,也陆陆续续面试过不少人,就简历来说,第一眼学历不太够,你只能靠你的实习或者论文或者项目经历,然后你没有论文,没有含金量高的比赛和奖项,只能看实习和项目,实习来说,你写的实习经历完全不清楚你想找什么工作?行研?数据分析?且写的太少了,再看项目,这些项目先不说上过大学读过研究生的都知道很水,然后对你想找的岗位有什么帮助呢?项目和实习也完全不匹配啊,你好像在努力将你所有的经历都放在简历里想表现你的优秀,但是对于你想找的岗位来说,有什么用呢?最后只能获得岗位不匹配的评价。所以你需要明白你想要找的岗位要求是什么,是做什么的,比如产品经理,然后再看你的经历里有什么匹配的上这个岗位,或者对这个岗位以及这个岗位所在的公司有价值,再写到你的简历上
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务