博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CodeForces - 1101B
阅读量:7294 次
发布时间:2019-06-30

本文共 1964 字,大约阅读时间需要 6 分钟。

题目:

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
#include
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
A;i--) { if(a[i]==']'){ B=i;break; } } for(int i=A+1;i
C;i--) { if(a[i]==':'){ D=i;break; } } for(int i=C;i

  

 

转载于:https://www.cnblogs.com/noback-go/p/10497097.html

你可能感兴趣的文章
linux下IPTABLES配置详解
查看>>
由网络引起的打印故障和邮件问题
查看>>
xml相关
查看>>
如何将App从一个账号迁移到另一个账号?
查看>>
linux系统修改字符集
查看>>
phantomjs-截图比例
查看>>
javascript for of
查看>>
EF6 秘籍 2th:实体数据建模基础 (十二)使用条件过滤对象集合
查看>>
30天了解30种技术系列---(1)现代web应用服务器-Express.js
查看>>
某android平板项目开发笔记----aChartEngine图表显示(2)
查看>>
マクロ使用基準
查看>>
将博客搬至CSDN
查看>>
如何mac下安装virtual,并识别usb接口
查看>>
Ansible批量部署zabbix-agent
查看>>
使用PowerShell对比两个服务器系统进程和软件清单
查看>>
线程池的概述和使用学习笔记
查看>>
oracle基础之日志系列
查看>>
【NetApp】移动磁盘柜到一个新的控制器
查看>>
实在太伟大了,感谢楼主共享深度爬取和广度爬取
查看>>
crontab调用python时出现ImportError: No module named XXX的问题
查看>>