当前位置: 代码迷 >> 综合 >> 2022.02.01翻译Longest Regular Bracket Sequence
  详细解决方案

2022.02.01翻译Longest Regular Bracket Sequence

热度:11   发布时间:2023-12-05 15:34:02.0

Longest Regular Bracket Sequence
题目(https://acs.jxnu.edu.cn/problem/CF5C)描述:
This is yet another problem dealing with regular bracket sequences.

We should remind you that a bracket sequence is called regular, if by inserting ?+? and ?1? into it we can get a correct mathematical expression. For example, sequences ?(())()?, ?()? and ?(()(()))? are regular, while ?)(?, ?(()? and ?(()))(? are not.

You are given a string of ?(? and ?)? characters. You are to find its longest substring that is a regular bracket sequence. You are to find the number of such substrings as well.

输入:
The first line of the input file contains a non-empty string, consisting of ?(? and ?)? characters. Its length does not exceed 106.

输出:
Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1".

样例输入:
)((())))(()())
样例输出:
6 2
样例输入:
))(
样例输出:
0 1

翻译:
这里有另一种处理规则括号序列的问题。

如果一个在一个括号序列中插入‘+’和‘1’可以把这个序列变成正确的数学表达式,则我们称这个括号序列使是规则的,例如序列?(())()?, ?()? 和 ?(()(()))?都是规则的,但序列?(())()?, ?()? 和 ?(()(()))?是不规则的。

给你一串由‘(’和‘)’组成的序列。找到它的最长的、是规则括号序列的子串,和子串的数量。

输入:
第一行输入一行不带空格的字符串,字符串由‘(’和‘)’组成。字符串的长度不超过106。

输出:
输出输入字符串的最长的、是规则括号序列的子串的长度,和子串的数量。如果找不到这样的子串,输出一行”0 1“。

样例输入:
)((())))(()())
样例输出:
6 2
样例输入:
))(
样例输出:
0 1

  相关解决方案