题目:

B. Accordion

time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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

题目大意:

由[::]这样的顺序可以构造手风琴,冒号之间可以有|用来增加手风琴的长度,给出一个串,问串构成的手风琴最长为多少。

思路:

首先,要判断能否构成手风琴,也就是说满足格式[::],不满足就输出-1,满足的话在两个冒号之间数有多少个|,最后加上4就是最长的手风琴长度。要注意,串给出的手风琴可能不止一个,所有要从前向后寻找[,从后往前寻找]。

AC代码如下:
#include<stdio.h>
#include<string.h> int main()
{
char a[500010];
int A=-1,B=-1,C=-1,D=-1,cnt=0;
scanf("%s",a);
int len=strlen(a);
for(int i=0;i<len;i++)
{
if(a[i]=='['){
A=i;break;
}
}
for(int i=len-1;i>A;i--)
{
if(a[i]==']'){
B=i;break;
}
}
for(int i=A+1;i<B;i++)
{
if(a[i]==':'){
C=i;break;
}
}
for(int i=B-1;i>C;i--)
{
if(a[i]==':'){
D=i;break;
}
}
for(int i=C;i<D;i++)
{
if(a[i]=='|') cnt++;
}
if(A==-1||B==-1||C==-1||D==-1) printf("-1\n");
else printf("%d\n",cnt+4);
return 0;
}

  


CodeForces - 1101B的更多相关文章

  1. Accordion CodeForces - 1101B (实现)

    An accordion is a string (yes, in the real world accordions are musical instruments, but let's forge ...

  2. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  3. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  4. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  5. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  6. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  7. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  8. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  9. CodeForces - 696B Puzzles

    http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...

随机推荐

  1. 湖南省队集训 Day 2

    从这里开始 Problem A 走路 Problem B 游戏 Problem C 有趣的字符串题 暴力分又没骗满sad..... Problem A 走路 $O(n^2)$动态规划是显然的. 更新方 ...

  2. FL Studio里的常规设置介绍

    上期我们介绍了FL Studio中的项目设置,今天我们来介绍FL Studio中的常规设置.要打开常规设置,我们需要在主菜单中选择选项>常规选项,当然也可以直接按快捷键F10. “常规设置”页面 ...

  3. 使用QPlainText代替QText

    1.现象 在项目开发中,经常使用QText来显示解析的数据,比如从网络中获取到一个数据包,解析成中文加以显示,当时间过久或者字符串比较多的时候,就会产生一定的卡顿,所以需要限制QText的行数,或者清 ...

  4. ip xfrm命令是做什么的?

    答: 设置xfrm.xfrm(transform configuration)是一个IP框架,用来转换数据包的格式,也就是使用算法来加密数据包,该框架用作IPsec协议的一部分 ip xfrm sta ...

  5. 第一次跑eureka

  6. HttpClient exception:ExceptionType:System.Threading.Tasks.TaskCanceledException: The operation was canceled. ---> System.IO.IOException: Unable to read data from the transport connection: Operation ca

    error msg: System.Threading.Tasks.TaskCanceledException: The operation was canceled. ---> System. ...

  7. python 画广东省等压线图

    最近开发时要实现一个业务逻辑: 调用中国气象数据网API接口获取广东省实时气象数据 根据数据,基于广东省地图渲染等压线图 最终效果图是这样的: 首先是获取实时气压数据,由于中国气象数据网每次只能获得3 ...

  8. myeclipse编码问题

    在中文操作系统中,Eclipse中的Java类型文件的编码的默认设置是GBK, 但是对Properties资源文件的编码的默认设置是ISO-8859-1. 所以编辑Java文件中的中文不会出现问题,但 ...

  9. PHP curl Post请求和Get请求~

    //获取的参数 $api_key = '8a82d53a57b06c1d835d129f7e43d49c'; $orderNum = pdo_fetch('select ddlm_order_no f ...

  10. krpano生成全景图

    1.下载krpano工具 第一次我下载的有水印,但是第二次下载的便没了,原因我也不清楚.下载好后不要急着打开.exe程序 2.生成全景图 将全景图拖入MAKE VTUOR (NORMAL) DROPL ...