B. Accordion

B. Accordion

B.手风琴

time limit per test: 3 seconds
每次测试的时间限制:3秒

memory limit per test: 256 megabytes
每次测试的内存限制:256兆字节

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
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 091), a colon (ASCII code 058). some (possibly zero) vertical line
表示为:开口括号(ASCII代码091)、冒号(ASCII代码058)的级联。一些(可能为零)垂直线

characters (ASCII code 124). another colon, and a closing bracket (ASCII code 093). The length of the accordion is the number of
字符(ASCII代码124)。另一个冒号和一个结束括号(ASCII代码093)。手风琴的长度是

characters in it.
characters in it.

For example, [: :], [😐 1 :] and [:111 : ] are accordions having length 4, 6 and 7. (: 1:), {:11:}, [:].]:|1: [ are not
例如,[:]、[:\x{e76f}和[:111:]是长度分别为4、6和7的手风琴。

acordions.
阿科迪翁。

You are given a string 8. You want to transform it into an accordion by removing some (possibly zero) characters from it. Note that you may
您将得到一个字符串8。您希望通过从其中移除一些字符(可能为零),将其转换为手风琴。请注意,您可以

not insert new characters or reorder existing ones. Is it possible to obtain an accordion by removing characters from 8, and if so, what is the
不插入新字符或重新排序现有字符。是否可以通过从8中移除字符来获得手风琴,如果可以的话,

maximum possible length of the result?
结果的最大可能长度?

Input
输入

The only line contains one string 8(1 < |s|≤500000). It consists of lowercase Latin letters and characters [, ], : and 1.
唯一的一行包含一个字符串8(1<\x{e76f}}≤500000)。它由小写拉丁字母和字符[,]、:和1组成。

Output
输出量

If it is not possible to obtain an accordion by removing some characters from 8, print - 1. Otherwise print maximum possible length of the
如果无法通过从8中移除某些字符获得手风琴,则打印-1。否则,打印

resulting accordion.
导致手风琴。

掐头去尾,遍历


int main()
{
    string a;
    cin>>a;
    int sum=0;
    int b=a.size()-1;
   while(a[b]!=']')
   {   --b;
       if(b<0)
       {
           cout<<-1<<endl;
           return 0;
       }
   }
   while(a[b]!=':')
   {   --b;
       if(b<0)
       {
           cout<<-1<<endl;
           return 0;
       }
   }
   int c=0;
   while(a[c]!='[')
   {   ++c;
       if(b<c+2)
       {
           cout<<-1<<endl;
           return 0;
       }
   }
   while(a[c]!=':')
   {   ++c;
       if(b<c+1)
       {
           cout<<-1<<endl;
           return 0;
       }
   }
    for (int i = c+1; i <b ; ++i) {
        if (a[i]=='|')
            sum++;
    }
    cout<<sum+4<<endl;

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值